-
Notifications
You must be signed in to change notification settings - Fork 107
/
main_test.go
66 lines (64 loc) · 2.01 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"reflect"
"testing"
)
func TestNormalizeNatsServers(t *testing.T) {
testCases := []struct {
testCase string
natsServers []string
want []string
}{
{
"No servers (should not happen but test it anyway)",
nil,
nil,
},
{
"Single server no spaces",
[]string{"nats://localhost:9876"},
[]string{"nats://localhost:9876"},
},
{
"Single server with spaces",
[]string{" nats://localhost:9876 "},
[]string{"nats://localhost:9876"},
},
{
"2 instances of --nats-servers",
[]string{"nats://localhost:9876", "nats://localhost:6789"},
[]string{"nats://localhost:9876", "nats://localhost:6789"},
},
{
"2 instances of --nats-servers with leading+trailing spaces",
[]string{" nats://localhost:9876 ", " nats://localhost:6789 "},
[]string{"nats://localhost:9876", "nats://localhost:6789"},
},
{
"Single instance of --nats-servers with multiple servers, no spaces",
[]string{"nats://localhost:3434,nats://localhost:2121"},
[]string{"nats://localhost:3434", "nats://localhost:2121"},
},
{
"Single instance of --nats-servers with multiple servers and spaces",
[]string{" nats://localhost:1111, nats://localhost:2222 ,nats://localhost:3333"},
[]string{"nats://localhost:1111", "nats://localhost:2222", "nats://localhost:3333"},
},
{
"Multiple instances of --nats-servers with multiple servers and spaces",
[]string{"nats://localhost:9999", " nats://localhost:8888 , nats://localhost:7777 ,nats://localhost:6666 ", " nats://localhost:5555 "},
[]string{"nats://localhost:9999", "nats://localhost:8888", "nats://localhost:7777", "nats://localhost:6666", "nats://localhost:5555"},
},
}
for _, tc := range testCases {
t.Run(tc.testCase, func(t *testing.T) {
natsServers, err := normalizeNatsServers(tc.natsServers)
if err != nil {
t.Fatalf("returned error: %#v", tc)
}
if !reflect.DeepEqual(natsServers, tc.want) {
t.Fatalf("\n wanted: %#v\n got: %#v", tc.want, natsServers)
}
})
}
}