-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
74 lines (69 loc) · 1.56 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
package rewriteng
import (
"testing"
"github.com/mholt/caddy"
)
func TestSetup(t *testing.T) {
}
func TestParse(t *testing.T) {
tests := []struct {
inputFileRules string
shouldErr bool
}{
// parse errors
{`rewriteng`, true},
{`rewriteng X`, true},
{`rewriteng ANY`, true},
{`rewriteng ANY X`, true},
{`rewriteng ANY ANY xxx`, true},
{
`rewriteng ANY ANY regex example\.org {
answer regex example\.com example.org
}`,
true,
},
{
`rewriteng ANY ANY regexx example\.org example.com {
answer regex example\.com example.org
}`,
true,
},
{
`rewriteng ANY ANY regex example\.org example.com {
answer regexx example\.com example.org
}`,
true,
},
{
`rewriteng ANY ANY regex example\.org example.com {
}`,
true,
},
// pass
{
`rewriteng ANY ANY regex example\.org example.com {
answer regex example\.com example.org
additional regex (.*)\.example\.com {1}.example.org
additional regex (.*)\.example\.net {1}.example.org
authority regex (.*)\.example\.net {1}.example.org
}`,
false,
},
// pass
{
`rewriteng ANY ANY regex example\.org example.com {
answer regex example\.com example.org
}`,
false,
},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.inputFileRules)
_, err := parse(c)
if err == nil && test.shouldErr {
t.Fatalf("Test %d expected errors, but got no error\n---\n%s\n", i, test.inputFileRules)
} else if err != nil && !test.shouldErr {
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
}
}
}