-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_test.go
124 lines (114 loc) · 2.39 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package file
import (
"testing"
"time"
"github.com/coredns/caddy"
"github.com/coredns/coredns/plugin/test"
)
func TestFileParse(t *testing.T) {
zoneFileName1, rm, err := test.TempFile(".", dbMiekNL)
if err != nil {
t.Fatal(err)
}
defer rm()
zoneFileName2, rm, err := test.TempFile(".", dbDnssexNLSigned)
if err != nil {
t.Fatal(err)
}
defer rm()
tests := []struct {
inputFileRules string
shouldErr bool
expectedZones Zones
}{
{
`file ` + zoneFileName1 + ` miek.nl.`,
false,
Zones{Names: []string{"miek.nl."}},
},
{
`file ` + zoneFileName2 + ` dnssex.nl.`,
false,
Zones{Names: []string{"dnssex.nl."}},
},
{
`file ` + zoneFileName2 + ` 10.0.0.0/8`,
false,
Zones{Names: []string{"10.in-addr.arpa."}},
},
// errors.
{
`file ` + zoneFileName1 + ` miek.nl {
transfer from 127.0.0.1
}`,
true,
Zones{},
},
{
`file`,
true,
Zones{},
},
{
`file ` + zoneFileName1 + ` example.net. {
no_reload
}`,
true,
Zones{},
},
{
`file ` + zoneFileName1 + ` example.net. {
no_rebloat
}`,
true,
Zones{},
},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.inputFileRules)
actualZones, err := fileParse(c)
if err == nil && test.shouldErr {
t.Fatalf("Test %d expected errors, but got no error", i)
} else if err != nil && !test.shouldErr {
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
} else {
if len(actualZones.Names) != len(test.expectedZones.Names) {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedZones.Names, actualZones.Names)
}
for j, name := range test.expectedZones.Names {
if actualZones.Names[j] != name {
t.Fatalf("Test %d expected %v for %d th zone, got %v", i, name, j, actualZones.Names[j])
}
}
}
}
}
func TestParseReload(t *testing.T) {
name, rm, err := test.TempFile(".", dbMiekNL)
if err != nil {
t.Fatal(err)
}
defer rm()
tests := []struct {
input string
reload time.Duration
}{
{
`file ` + name + ` example.org.`,
1 * time.Minute,
},
{
`file ` + name + ` example.org. {
reload 5s
}`,
5 * time.Second,
},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.input)
z, _ := fileParse(c)
if x := z.Z["example.org."].ReloadInterval; x != test.reload {
t.Errorf("Test %d expected reload to be %s, but got %s", i, test.reload, x)
}
}
}