Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/connhelper/connhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
}
return &ConnectionHelper{
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)
return commandconn.New(ctx, "ssh", sp.Args("docker", "system", "dial-stdio")...)
},
Host: "http://docker",
}, nil
Expand Down
7 changes: 4 additions & 3 deletions cli/connhelper/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ type Spec struct {
Port string
}

// Args returns args except "ssh" itself and "-- ..."
func (sp *Spec) Args() []string {
// Args returns args except "ssh" itself combined with optional additional command args
func (sp *Spec) Args(add ...string) []string {
var args []string
if sp.User != "" {
args = append(args, "-l", sp.User)
}
if sp.Port != "" {
args = append(args, "-p", sp.Port)
}
args = append(args, sp.Host)
args = append(args, "--", sp.Host)
args = append(args, add...)
return args
}
20 changes: 11 additions & 9 deletions cli/connhelper/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ func TestParseURL(t *testing.T) {
{
url: "ssh://foo",
expectedArgs: []string{
"foo",
"--", "foo",
},
},
{
url: "ssh://me@foo:10022",
expectedArgs: []string{
"-l", "me",
"-p", "10022",
"foo",
"--", "foo",
},
},
{
Expand Down Expand Up @@ -53,12 +53,14 @@ func TestParseURL(t *testing.T) {
},
}
for _, tc := range testCases {
sp, err := ParseURL(tc.url)
if tc.expectedError == "" {
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
} else {
assert.ErrorContains(t, err, tc.expectedError)
}
t.Run(tc.url, func(t *testing.T) {
sp, err := ParseURL(tc.url)
if tc.expectedError == "" {
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
} else {
assert.ErrorContains(t, err, tc.expectedError)
}
})
}
}