This repository has been archived by the owner on Apr 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup_test.go
154 lines (150 loc) · 2.1 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package dns64
import (
"testing"
"github.com/caddyserver/caddy"
)
func TestSetupDns64(t *testing.T) {
tests := []struct {
inputUpstreams string
shouldErr bool
prefix string
}{
{
`dns64`,
false,
"64:ff9b::/96",
},
{
`dns64 64:dead::/96`,
false,
"64:dead::/96",
},
{
`dns64 {
translateAll
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
translateAll
proxy . 8.8.8.8
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
proxy . 8.8.8.8
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
prefix 64:ff9b::/96
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
prefix 64:ff9b::/32
}`,
false,
"64:ff9b::/32",
},
{
`dns64 {
prefix 64:ff9b::/52
}`,
true,
"64:ff9b::/52",
},
{
`dns64 {
prefix 64:ff9b::/104
}`,
true,
"64:ff9b::/104",
},
{
`dns64 {
prefix 8.8.8.8/24
}`,
true,
"8.8.9.9/24",
},
{
`dns64 {
proxy . 8.8.8.8 8.8.4.4
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
proxy . some_not_useable_domain
}`,
true,
"64:ff9b::/96",
},
{
`dns64 {
prefix 64:ff9b::/96
proxy . 8.8.8.8
}`,
false,
"64:ff9b::/96",
},
{
`dns64 {
prefix 2002:ac12:b083::/96
proxy . 8.8.8.8
}`,
false,
"2002:ac12:b083::/96",
},
{
`dns64 {
prefix 2002:c0a8:a88a::/48
proxy . 8.8.8.8
}`,
false,
"2002:c0a8:a88a::/48",
},
{
`dns64 foobar {
prefix 64:ff9b::/96
proxy . 8.8.8.8
}`,
true,
"64:ff9b::/96",
},
{
`dns64 foobar`,
true,
"64:ff9b::/96",
},
{
`dns64 {
foobar
}`,
true,
"64:ff9b::/96",
},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.inputUpstreams)
dns64, err := dns64Parse(&c.Dispenser)
if (err != nil) != test.shouldErr {
t.Errorf("Test %d expected %v error, got %v for %s", i+1, test.shouldErr, err, test.inputUpstreams)
}
if err == nil {
if dns64.Prefix.String() != test.prefix {
t.Errorf("Test %d expected prefix %s, got %v", i+1, test.prefix, dns64.Prefix.String())
}
}
}
}