Files
opsxshell/test/utils/parseSshTarget.test.ts
T

41 lines
934 B
TypeScript

import { describe, it, expect } from 'vitest'
import { parseSshTarget } from '../../src/components/sessions/QuickConnectDialog'
describe('parseSshTarget', () => {
it('解析 host', () => {
expect(parseSshTarget('192.168.1.1')).toEqual({
host: '192.168.1.1',
port: 22,
username: 'root',
})
})
it('解析 user@host', () => {
expect(parseSshTarget('ubuntu@opsbase.cn')).toEqual({
host: 'opsbase.cn',
port: 22,
username: 'ubuntu',
})
})
it('解析 user@host:port', () => {
expect(parseSshTarget('root@opsbase.cn:5555')).toEqual({
host: 'opsbase.cn',
port: 5555,
username: 'root',
})
})
it('解析 host:port', () => {
expect(parseSshTarget('example.com:2222')).toEqual({
host: 'example.com',
port: 2222,
username: 'root',
})
})
it('空串返回 null', () => {
expect(parseSshTarget(' ')).toBeNull()
})
})