Files
ide/test/test.ssh.node.ts
T
2026-05-10 14:08:25 +00:00

48 lines
1.3 KiB
TypeScript

import { tap, expect } from '@git.zone/tstest/tapbundle';
import { buildSshArgs, listConnectableHosts, parseSshConfig } from '../packages/ssh/ts/index.js';
tap.test('should parse ssh config hosts', async () => {
const hosts = parseSshConfig(`
Host *
ServerAliveInterval 30
Host dev-box staging-box
HostName dev.example.com
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519
ProxyJump bastion
Host *.internal
User ignored
`);
const connectableHosts = listConnectableHosts(hosts);
expect(connectableHosts).toHaveLength(2);
expect(connectableHosts[0]!.alias).toEqual('dev-box');
expect(connectableHosts[0]!.hostName).toEqual('dev.example.com');
expect(connectableHosts[0]!.user).toEqual('deploy');
expect(connectableHosts[0]!.port).toEqual(2222);
expect(connectableHosts[0]!.identityFiles[0]!).toEndWith('/.ssh/id_ed25519');
expect(connectableHosts[0]!.proxyJump).toEqual('bastion');
});
tap.test('should build ssh args with destination and command', async () => {
const args = buildSshArgs(
{
id: 'dev-box',
hostAlias: 'dev-box',
user: 'deploy',
port: 2222,
},
'uname -a',
);
expect(args).toContain('-p');
expect(args).toContain('2222');
expect(args).toContain('deploy@dev-box');
expect(args[args.length - 1]).toEqual('uname -a');
});
export default tap.start();