28 lines
883 B
TypeScript
28 lines
883 B
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { ErrorCode, handleError } from '../../src/utils/error-handler'
|
|
|
|
vi.mock('../../src/utils/logger', () => ({
|
|
logger: { error: vi.fn() },
|
|
}))
|
|
|
|
describe('connection error classification', () => {
|
|
it.each([
|
|
'connection timed out',
|
|
'SSH handshake timeout',
|
|
'连接超时',
|
|
])('classifies timeout: %s', (message) => {
|
|
expect(handleError(new Error(message)).code).toBe(ErrorCode.CONNECTION_TIMEOUT)
|
|
})
|
|
|
|
it.each([
|
|
'getaddrinfo ENOTFOUND host.invalid',
|
|
'无法解析主机 host.invalid',
|
|
])('classifies DNS failures: %s', (message) => {
|
|
expect(handleError(new Error(message)).code).toBe(ErrorCode.HOST_UNREACHABLE)
|
|
})
|
|
|
|
it('classifies connection refusal separately from timeout', () => {
|
|
expect(handleError(new Error('Connection refused')).code).toBe(ErrorCode.CONNECTION_FAILED)
|
|
})
|
|
})
|