github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/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 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  		sp, err := ParseURL(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  }