From a4a8e70f9cff776b7323b368684b69ecfee91677 Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Wed, 28 Jan 2026 19:00:53 +1000 Subject: [PATCH] fix: sshcli tests --- internal/sshexec/sshcli_test.go | 42 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/internal/sshexec/sshcli_test.go b/internal/sshexec/sshcli_test.go index 22cbda38..073a90c0 100644 --- a/internal/sshexec/sshcli_test.go +++ b/internal/sshexec/sshcli_test.go @@ -18,29 +18,49 @@ func TestSSHCLIRemote_buildSSHArgs(t *testing.T) { expected []string }{ { - name: "default port, no key", + name: "host only", + host: "example.com", + expected: []string{"-o", "ConnectTimeout=5", "example.com"}, + }, + { + name: "with user", user: "root", host: "example.com", - port: 22, - keyPath: "", expected: []string{"-o", "ConnectTimeout=5", "root@example.com"}, }, { - name: "custom port", + name: "with port", + host: "example.com", + port: 2222, + expected: []string{"-o", "ConnectTimeout=5", "-p", "2222", "example.com"}, + }, + { + name: "with key", + host: "example.com", + keyPath: "/path/to/key", + expected: []string{"-o", "ConnectTimeout=5", "-i", "/path/to/key", "example.com"}, + }, + { + name: "user and port", user: "ubuntu", host: "192.168.1.10", port: 2222, - keyPath: "", expected: []string{"-o", "ConnectTimeout=5", "-p", "2222", "ubuntu@192.168.1.10"}, }, { - name: "with key path", + name: "user and key", user: "root", host: "example.com", - port: 22, keyPath: "/path/to/key", expected: []string{"-o", "ConnectTimeout=5", "-i", "/path/to/key", "root@example.com"}, }, + { + name: "port and key", + host: "example.com", + port: 22, + keyPath: "~/.ssh/id_rsa", + expected: []string{"-o", "ConnectTimeout=5", "-p", "22", "-i", "~/.ssh/id_rsa", "example.com"}, + }, { name: "all options", user: "admin", @@ -49,14 +69,6 @@ func TestSSHCLIRemote_buildSSHArgs(t *testing.T) { keyPath: "~/.ssh/id_rsa", expected: []string{"-o", "ConnectTimeout=5", "-p", "2222", "-i", "~/.ssh/id_rsa", "admin@server.local"}, }, - { - name: "port zero (default)", - user: "root", - host: "example.com", - port: 0, - keyPath: "", - expected: []string{"-o", "ConnectTimeout=5", "root@example.com"}, - }, } for _, tt := range tests {