Files
docker-cli/cli/connhelper/ssh/ssh_test.go
Akihiro Suda 6f61cf053a support SSH connection
e.g. docker -H ssh://me@server

The `docker` CLI also needs to be installed on the remote host to
provide `docker system dial-stdio`, which proxies the daemon socket to stdio.

Please refer to docs/reference/commandline/dockerd.md .

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-08-02 13:10:06 +09:00

65 lines
1.2 KiB
Go

package ssh
import (
"testing"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)
func TestParseSSHURL(t *testing.T) {
testCases := []struct {
url string
expectedArgs []string
expectedError string
}{
{
url: "ssh://foo",
expectedArgs: []string{
"foo",
},
},
{
url: "ssh://me@foo:10022",
expectedArgs: []string{
"-l", "me",
"-p", "10022",
"foo",
},
},
{
url: "ssh://me:passw0rd@foo",
expectedError: "ssh helper does not accept plain-text password",
},
{
url: "ssh://foo/bar",
expectedError: "extra path",
},
{
url: "ssh://foo?bar",
expectedError: "extra query",
},
{
url: "ssh://foo#bar",
expectedError: "extra fragment",
},
{
url: "ssh://",
expectedError: "host is not specified",
},
{
url: "foo://bar",
expectedError: "expected scheme ssh",
},
}
for _, tc := range testCases {
sp, err := parseSSHURL(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)
}
}
}