github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/cli/connhelper/ssh/ssh_test.go (about) 1 package ssh 2 3 import ( 4 "testing" 5 6 "gotest.tools/assert" 7 is "gotest.tools/assert/cmp" 8 ) 9 10 func TestParseSSHURL(t *testing.T) { 11 testCases := []struct { 12 url string 13 expectedArgs []string 14 expectedError string 15 }{ 16 { 17 url: "ssh://foo", 18 expectedArgs: []string{ 19 "foo", 20 }, 21 }, 22 { 23 url: "ssh://me@foo:10022", 24 expectedArgs: []string{ 25 "-l", "me", 26 "-p", "10022", 27 "foo", 28 }, 29 }, 30 { 31 url: "ssh://me:passw0rd@foo", 32 expectedError: "ssh helper does not accept plain-text password", 33 }, 34 { 35 url: "ssh://foo/bar", 36 expectedError: "extra path", 37 }, 38 { 39 url: "ssh://foo?bar", 40 expectedError: "extra query", 41 }, 42 { 43 url: "ssh://foo#bar", 44 expectedError: "extra fragment", 45 }, 46 { 47 url: "ssh://", 48 expectedError: "host is not specified", 49 }, 50 { 51 url: "foo://bar", 52 expectedError: "expected scheme ssh", 53 }, 54 } 55 for _, tc := range testCases { 56 sp, err := parseSSHURL(tc.url) 57 if tc.expectedError == "" { 58 assert.NilError(t, err) 59 assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args())) 60 } else { 61 assert.ErrorContains(t, err, tc.expectedError) 62 } 63 } 64 }