-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
49 lines (41 loc) · 964 Bytes
/
main_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
package main
import (
"strings"
"testing"
)
func Test_parseClFile(t *testing.T) {
clfile := `
prod:
prod0.example.com ~/.ssh/id_ed25519
prod1.example.com ~/.ssh/id_ed25519
prod2.example.com ~/.ssh/id_ed25519
uat:
uat0.example.com ~/.ssh/id_rsa
uat1.example.com ~/.ssh/id_rsa
uat2.example.com ~/.ssh/id_rsa
# Comment line, this is ignored.
mixed:
mixed0.example.com
mixed1.example.com:444
mixed2.example.com
mixed3.example.com ~/.ssh/id_ed25519
`
envs := parseClFile(strings.NewReader(clfile))
tests := []struct{
key string
count int
}{
{"prod", 3},
{"uat", 3},
{"mixed", 4},
}
for i, test := range tests {
hosts, ok := envs[test.key]
if !ok {
t.Fatalf("tests[%d] - expected key %q in map, it was not\n", i, test.key)
}
if len(hosts) != test.count {
t.Fatalf("tests[%d] - unexpected host count, expected=%d, got=%d\n", i, test.count, len(hosts))
}
}
}