-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup_test.go
232 lines (227 loc) · 5.23 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package ens
import (
"testing"
"github.com/coredns/caddy"
)
func TestENSParse(t *testing.T) {
tests := []struct {
key string
inputFileRules string
err string
connection string
ethlinknameservers []string
ipfsgatewayas []string
ipfsgatewayaaaas []string
}{
{ // 0
".",
`ens {
}`,
"Testfile:2 - Error during parsing: no connection",
"",
nil,
nil,
nil,
},
{ // 1
".",
`ens {
connection
}`,
"Testfile:2 - Error during parsing: invalid connection; no value",
"",
nil,
nil,
nil,
},
{ // 2
".eth.link",
`ens {
connection /home/test/.ethereum/geth.ipc
ethlinknameservers ns1.ethdns.xyz
}`,
"",
"/home/test/.ethereum/geth.ipc",
[]string{"ns1.ethdns.xyz."},
nil,
nil,
},
{ // 3
".",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
}`,
"",
"http://localhost:8545/",
[]string{"ns1.ethdns.xyz.", "ns2.ethdns.xyz."},
nil,
nil,
},
{ // 4
".",
`ens {
connection http://localhost:8545/
ipfsgatewaya
}`,
"Testfile:3 - Error during parsing: invalid IPFS gateway A; no value",
"",
nil,
nil,
nil,
},
{ // 5
".",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
ipfsgatewaya 193.62.81.1
}`,
"",
"",
nil,
[]string{"193.62.81.1"},
nil,
},
{ // 6
".",
`ens {
connection http://localhost:8545/
ipfsgatewayaaaa
}`,
"Testfile:3 - Error during parsing: invalid IPFS gateway AAAA; no value",
"",
nil,
nil,
nil,
},
{ // 7
".",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
ipfsgatewayaaaa fe80::b8fb:325d:fb5a:40e7
}`,
"",
"",
nil,
nil,
[]string{"fe80::b8fb:325d:fb5a:40e7"},
},
{ // 8
"tls://.:8053",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
ipfsgatewayaaaa fe80::b8fb:325d:fb5a:40e7
}`,
"",
"",
nil,
nil,
[]string{"fe80::b8fb:325d:fb5a:40e7"},
},
{ // 9
".:8053",
`ens {
connection http://localhost:8545/ bad
ipfsgatewayaaaa fe80::b8fb:325d:fb5a:40e7
}`,
"Testfile:2 - Error during parsing: invalid connection; multiple values",
"",
nil,
nil,
nil,
},
{ // 10
".:8053",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
ipfsgatewaya 193.62.81.1 193.62.81.2
}`,
"",
"",
nil,
[]string{"193.62.81.1", "193.62.81.2"},
nil,
},
{ // 11
".:8053",
`ens {
connection http://localhost:8545/
ethlinknameservers ns1.ethdns.xyz ns2.ethdns.xyz
ipfsgatewayaaaa fe80::b8fb:325d:fb5a:40e7 fe80::b8fb:325d:fb5a:40e8
}`,
"",
"",
nil,
nil,
[]string{"fe80::b8fb:325d:fb5a:40e7", "fe80::b8fb:325d:fb5a:40e8"},
},
{ // 12
".:8053",
`ens {
connection http://localhost:8545/
ipfsgatewayaaaa fe80::b8fb:325d:fb5a:40e7 fe80::b8fb:325d:fb5a:40e8
bad
}`,
"Testfile:4 - Error during parsing: unknown value bad",
"",
nil,
nil,
nil,
},
}
for i, test := range tests {
c := caddy.NewTestController("ens", test.inputFileRules)
c.Key = test.key
connection, ethlinknameservers, ipfsgatewayas, ipfsgatewayaaaas, err := ensParse(c)
if test.err != "" {
if err == nil {
t.Fatalf("Failed to obtain expected error at test %d", i)
}
if err.Error() != test.err {
t.Fatalf("Unexpected error \"%s\" at test %d", err.Error(), i)
}
} else {
if err != nil {
t.Fatalf("Unexpected error \"%s\" at test %d", err.Error(), i)
} else {
if test.connection != "" && connection != test.connection {
t.Fatalf("Test %d connection expected %v, got %v", i, test.connection, connection)
}
if test.ethlinknameservers != nil {
if len(ethlinknameservers) != len(test.ethlinknameservers) {
t.Fatalf("Test %d ethlinknameservers expected %v entries, got %v", i, len(test.ethlinknameservers), len(ethlinknameservers))
}
for j := range test.ethlinknameservers {
if ethlinknameservers[j] != test.ethlinknameservers[j] {
t.Fatalf("Test %d ethlinknameservers expected %v, got %v", i, test.ethlinknameservers[j], ethlinknameservers[j])
}
}
}
if test.ipfsgatewayas != nil {
if len(ipfsgatewayas) != len(test.ipfsgatewayas) {
t.Fatalf("Test %d ipfsgatewayas expected %v entries, got %v", i, len(test.ipfsgatewayas), len(ipfsgatewayas))
}
for j := range test.ipfsgatewayas {
if ipfsgatewayas[j] != test.ipfsgatewayas[j] {
t.Fatalf("Test %d ipfsgatewayas expected %v, got %v", i, test.ipfsgatewayas[j], ipfsgatewayas[j])
}
}
}
if test.ipfsgatewayaaaas != nil {
if len(ipfsgatewayaaaas) != len(test.ipfsgatewayaaaas) {
t.Fatalf("Test %d ipfsgatewayaaaas expected %v entries, got %v", i, len(test.ipfsgatewayaaaas), len(ipfsgatewayaaaas))
}
for j := range test.ipfsgatewayaaaas {
if ipfsgatewayaaaas[j] != test.ipfsgatewayaaaas[j] {
t.Fatalf("Test %d ipfsgatewayaaaas expected %v, got %v", i, test.ipfsgatewayaaaas[j], ipfsgatewayaaaas[j])
}
}
}
}
}
}
}