generated from vshn/go-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
81 lines (74 loc) · 1.82 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"testing"
"github.com/appuio/tailscale-service-observer/tailscaleupdater"
"github.com/go-logr/logr/testr"
"github.com/stretchr/testify/assert"
)
func Test_parseEnv(t *testing.T) {
tcases := []struct {
raw string
expected []string
}{
{raw: "", expected: []string{}},
{raw: "foo", expected: []string{"foo"}},
{raw: "foo,", expected: []string{"foo"}},
{raw: ", foo, ", expected: []string{"foo"}}, {raw: "foo,bar", expected: []string{"foo", "bar"}},
{raw: "foo, bar", expected: []string{"foo", "bar"}},
{raw: "foo, bar, ", expected: []string{"foo", "bar"}},
}
for _, tc := range tcases {
parsed := parseEnv(tc.raw)
assert.Equal(t, tc.expected, parsed)
}
}
func Test_advertiseAdditionalRoutes(t *testing.T) {
l := testr.New(t)
tcases := map[string]struct {
raw string
expected map[string]struct{}
}{
"empty": {
raw: "",
expected: map[string]struct{}{},
},
"ip": {
raw: "198.51.100.1",
expected: map[string]struct{}{
"198.51.100.1/32": {},
},
},
"multiple_ip": {
raw: "198.51.100.1, 198.51.100.2",
expected: map[string]struct{}{
"198.51.100.1/32": {},
"198.51.100.2/32": {},
},
},
"prefix": {
raw: "198.51.100.0/29",
expected: map[string]struct{}{
"198.51.100.0/29": {},
},
},
"multiple_prefix": {
raw: "198.51.100.0/29,198.51.100.128/29",
expected: map[string]struct{}{
"198.51.100.0/29": {},
"198.51.100.128/29": {},
},
},
"mixed": {
raw: "198.51.100.1,198.51.100.128/29",
expected: map[string]struct{}{
"198.51.100.1/32": {},
"198.51.100.128/29": {},
},
},
}
for _, tc := range tcases {
tsUpdater := tailscaleupdater.NewUnchecked([]string{"test"}, "foobar", l)
advertiseAdditionalRoutes(l, tsUpdater, tc.raw)
assert.Equal(t, tsUpdater.GetRoutes(), tc.expected)
}
}