forked from contentful-labs/coredns-nodecache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
86 lines (82 loc) · 1.79 KB
/
setup_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
package nodecache
import (
"net"
"reflect"
"testing"
"github.com/caddyserver/caddy"
"github.com/coredns/coredns/core/dnsserver"
)
func TestSetupParse(t *testing.T) {
for _, test := range []struct {
config string
expected config
}{
{
`nodecache`, // TODO caddy enable bind plugin here
config{
ifName: "nodecache",
setupIPTables: true,
port: 53,
localIPs: []net.IP{net.ParseIP("192.168.10.100")},
skipTeardown: false,
},
},
{
`nodecache skipteardown`,
config{
ifName: "nodecache",
setupIPTables: true,
port: 53,
localIPs: []net.IP{net.ParseIP("192.168.10.100")},
skipTeardown: true,
},
},
} {
c := caddy.NewTestController("dns", test.config)
cfg := getDefaultCfg()
if shouldSkipTearDown(c) {
cfg.skipTeardown = true
}
if cfg.parseSrvConfig(dnsserver.GetConfig(c)) != nil {
t.Error("Error while trying to parse server config")
}
if !reflect.DeepEqual(&cfg, &test.expected) {
t.Error("Expected", &test.expected, " gots ", &cfg)
}
// TODO ensure interface
}
}
func TestConfigParse(t *testing.T) {
for _, test := range []struct {
input dnsserver.Config
output config
shouldErr bool
}{
{
dnsserver.Config{
Port: "53",
ListenHosts: []string{"168.255.20.10"},
},
config{
ifName: "nodecache",
setupIPTables: true,
port: 53,
localIPs: []net.IP{net.ParseIP("168.255.20.10")},
skipTeardown: false,
},
false,
},
} {
cfg := getDefaultCfg()
err := cfg.parseSrvConfig(&test.input)
if test.shouldErr {
if err != nil {
t.Error("Should've returned an error")
}
} else {
if !reflect.DeepEqual(&cfg, &test.output) {
t.Error("Expected", &test.output, " gots ", &cfg)
}
}
}
}