github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/connhelper/ssh/ssh_test.go (about) 1 package ssh 2 3 import ( 4 "testing" 5 6 "gotest.tools/v3/assert" 7 is "gotest.tools/v3/assert/cmp" 8 ) 9 10 func TestParseURL(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: "plain-text password is not supported", 33 }, 34 { 35 url: "ssh://foo/bar", 36 expectedError: `extra path after the host: "/bar"`, 37 }, 38 { 39 url: "ssh://foo?bar", 40 expectedError: `extra query after the host: "bar"`, 41 }, 42 { 43 url: "ssh://foo#bar", 44 expectedError: `extra fragment after the host: "bar"`, 45 }, 46 { 47 url: "ssh://", 48 expectedError: "no host specified", 49 }, 50 { 51 url: "foo://bar", 52 expectedError: `expected scheme ssh, got "foo"`, 53 }, 54 } 55 for _, tc := range testCases { 56 t.Run(tc.url, func(t *testing.T) { 57 sp, err := ParseURL(tc.url) 58 if tc.expectedError == "" { 59 assert.NilError(t, err) 60 assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args())) 61 } else { 62 assert.ErrorContains(t, err, tc.expectedError) 63 } 64 }) 65 } 66 }