-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
114 lines (84 loc) · 2.7 KB
/
options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseSSHDestionation(t *testing.T) {
t.Parallel()
/* URL like destination */
login, host, port := parseSSHDestination("ssh://login@host:port")
assert.Equal(t, "login", login)
assert.Equal(t, "host", host)
assert.Equal(t, "port", port)
login, host, port = parseSSHDestination("ssh://host:port")
assert.Equal(t, "", login)
assert.Equal(t, "host", host)
assert.Equal(t, "port", port)
login, host, port = parseSSHDestination("ssh://host")
assert.Equal(t, "", login)
assert.Equal(t, "host", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("ssh://login@domain@host:port")
assert.Equal(t, "login@domain", login)
assert.Equal(t, "host", host)
assert.Equal(t, "port", port)
login, host, port = parseSSHDestination("ssh://login@domain@[fec1::1]:port")
assert.Equal(t, "login@domain", login)
assert.Equal(t, "fec1::1", host)
assert.Equal(t, "port", port)
login, host, port = parseSSHDestination("ssh://login@domain@[fec1::1]")
assert.Equal(t, "login@domain", login)
assert.Equal(t, "fec1::1", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("ssh://@[fec1::1]")
assert.Equal(t, "", login)
assert.Equal(t, "fec1::1", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("[fec1::1]")
assert.Equal(t, "", login)
assert.Equal(t, "[fec1::1]", host)
assert.Equal(t, "", port)
/* Non-URL like destination */
login, host, port = parseSSHDestination("login@host")
assert.Equal(t, "login", login)
assert.Equal(t, "host", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("host")
assert.Equal(t, "", login)
assert.Equal(t, "host", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("host:port")
assert.Equal(t, "", login)
assert.Equal(t, "host:port", host)
assert.Equal(t, "", port)
login, host, port = parseSSHDestination("login@host:port")
assert.Equal(t, "login", login)
assert.Equal(t, "host:port", host)
assert.Equal(t, "", port)
}
func TestNewOptions(t *testing.T) {
t.Parallel()
parsedArgs := ParsedArgs{
Options: map[string]string{
"-l": "login",
"--use-eice": "true",
},
Destination: "host",
CommandWithArgs: []string{"command"},
SSHArgs: []string{"-t"},
}
options, err := NewOptions(parsedArgs)
require.NoError(t, err)
assert.Equal(t, "host", options.Destination)
assert.Equal(t, "login", options.Login)
assert.True(t, options.UseEICE)
parsedArgs = ParsedArgs{
Options: map[string]string{
"--destination-type": "unknown-dst-type",
},
Destination: "host",
}
_, err = NewOptions(parsedArgs)
require.Error(t, err)
}