-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathconfig_test.go
97 lines (88 loc) · 1.9 KB
/
config_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
package tunnel
import (
"reflect"
"strings"
"testing"
"github.com/kevinburke/ssh_config"
)
func TestSSHConfigFile(t *testing.T) {
var config = `
Host example1
Hostname 172.17.0.1
Port 3306
User john
IdentityFile /path/.ssh/id_rsa
Host example2
LocalForward 8080 127.0.0.1:8080
Host example3
LocalForward 9090 127.0.0.1:9090
Host example4
RemoteForward 80 127.0.0.1:8080
Host example5
RemoteForward 192.168.1.100:80 my-server:8080
`
c, _ := ssh_config.Decode(strings.NewReader(config))
cfg := &SSHConfigFile{sshConfig: c}
tests := []struct {
host string
expected *SSHHost
}{
{
"example1",
&SSHHost{
Hostname: "172.17.0.1",
Port: "3306",
User: "john",
Key: "/path/.ssh/id_rsa",
LocalForward: nil,
},
},
{
"example2",
&SSHHost{
Hostname: "",
Port: "",
User: "",
Key: "",
LocalForward: &ForwardConfig{Source: "127.0.0.1:8080", Destination: "127.0.0.1:8080"},
},
},
{
"example3",
&SSHHost{
Hostname: "",
Port: "",
User: "",
Key: "",
LocalForward: &ForwardConfig{Source: "127.0.0.1:9090", Destination: "127.0.0.1:9090"},
},
},
{
"example4",
&SSHHost{
Hostname: "",
Port: "",
User: "",
Key: "",
RemoteForward: &ForwardConfig{Source: "127.0.0.1:80", Destination: "127.0.0.1:8080"},
},
},
{
"example5",
&SSHHost{
Hostname: "",
Port: "",
User: "",
Key: "",
RemoteForward: &ForwardConfig{Source: "192.168.1.100:80", Destination: "my-server:8080"},
},
},
}
var value *SSHHost
for _, test := range tests {
value = cfg.Get(test.host)
if !reflect.DeepEqual(test.expected, value) {
t.Errorf("unexpected result for %s:\n\texpected: %s\n\tvalue : %s", test.host, test.expected, value)
}
}
}