-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup_test.go
100 lines (95 loc) · 2.35 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
package alternate
import (
"fmt"
"strings"
"testing"
"github.com/coredns/caddy"
)
type setupTestCase struct {
config string
expectedError string
}
func TestSetupAlternate(t *testing.T) {
testCases := []setupTestCase{
{
config: `alternate REFUSED . 192.168.1.1:53`,
},
{
config: `alternate SERVFAIL . 192.168.1.1:53`,
},
{
config: `alternate NXDOMAIN . 192.168.1.1:53`,
},
{
config: `alternate original NXDOMAIN . 192.168.1.1:53`,
},
{
config: `alternate REFUSE . 192.168.1.1:53`,
expectedError: `is not a valid rcode`,
},
{
config: `alternate SRVFAIL . 192.168.1.1:53`,
expectedError: `is not a valid rcode`,
},
{
config: `alternate NODOMAIN . 192.168.1.1:53`,
expectedError: `is not a valid rcode`,
},
{
config: `alternate original NODOMAIN . 192.168.1.1:53`,
expectedError: `is not a valid rcode`,
},
{
config: `alternate REFUSED . 192.168.1.1:53 {
max_fails 5
force_tcp
}`,
expectedError: `additional parameters not allowed`,
},
{
config: `alternate REFUSED . tls://192.168.1.1:443`,
expectedError: `only dns transport allowed`,
},
{
config: `alternate REFUSED . abc`,
expectedError: `not an IP address or file`,
},
{
config: `alternate REFUSED . 192.168.1.1:53
alternate REFUSED . 192.168.1.2:53`,
expectedError: `specified more than once`,
},
{
config: `alternate REFUSED . 192.168.1.1:53
alternate original REFUSED . 192.168.1.2:53`,
expectedError: `specified more than once`,
},
{
config: `alternate SERVFAIL, REFUSED . 192.168.1.1:53`,
expectedError: `is not a valid rcode`,
},
{
config: `alternate SERVFAIL,REFUSED . 192.168.1.1:53`,
},
{
config: `alternate original SERVFAIL,REFUSED . 192.168.1.1:53`,
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.config), func(t *testing.T) {
c := caddy.NewTestController("dns", tc.config)
err := setup(c)
if err == nil {
if tc.expectedError != "" {
t.Errorf("Expected error '%s', but got no error", tc.expectedError)
}
} else {
if tc.expectedError == "" {
t.Errorf("Expected no error, but got '%s'", err)
} else if !strings.Contains(err.Error(), tc.expectedError) {
t.Errorf("Expected error '%s', but got '%s'", tc.expectedError, err)
}
}
})
}
}