-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolvconf_test.go
58 lines (54 loc) · 1.23 KB
/
resolvconf_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
package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetClusterDomain(t *testing.T) {
testCases := []struct {
content string
expected string
}{
{
content: "search svc.cluster.local #test comment",
expected: "svc.cluster.local",
},
{
content: "search default.svc.cluster.local svc.cluster.local cluster.local",
expected: "cluster.local",
},
{
content: "",
expected: "cluster.local",
},
}
for _, tc := range testCases {
domain, err := getClusterDomain([]byte(tc.content))
if err != nil {
t.Fatalf("get kube cluster domain error:%s", err)
}
assert.Equal(t, domain, tc.expected)
}
}
func TestGetSearchDomains(t *testing.T) {
testCases := []struct {
content string
expected []string
}{
{
content: "search svc.cluster.local #test comment",
expected: []string{"svc.cluster.local"},
},
{
content: "search default.svc.cluster.local svc.cluster.local cluster.local",
expected: []string{"default.svc.cluster.local", "svc.cluster.local", "cluster.local"},
},
{
content: "",
expected: []string{},
},
}
for _, tc := range testCases {
domains := getResolvSearchDomains([]byte(tc.content))
assert.ElementsMatch(t, domains, tc.expected)
}
}