-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema_test.go
71 lines (68 loc) · 1.76 KB
/
schema_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
package gochinadns
import (
"reflect"
"testing"
)
func Test_schemaToResolver(t *testing.T) {
tests := []struct {
input string
wantR *Resolver
wantErr bool
}{
{"8.8.8.8:53", &Resolver{
Addr: "8.8.8.8:53",
Protocols: []string{"udp"},
}, false},
{"udp@8.8.8.8:54", &Resolver{
Addr: "8.8.8.8:54",
Protocols: []string{"udp"},
}, false},
{"UDP+tcp@8.8.8.8:53", &Resolver{
Addr: "8.8.8.8:53",
Protocols: []string{"udp", "tcp"},
}, false},
{"UDP+udp+tcp@8.8.8.8:53", &Resolver{
Addr: "8.8.8.8:53",
Protocols: []string{"udp", "tcp"},
}, false},
{"tcp+udp@8.8.8.8:53", &Resolver{
Addr: "8.8.8.8:53",
Protocols: []string{"tcp", "udp"},
}, false},
{"@8.8.8.8:53", nil, true},
{"asdf@8.8.8.8:53", nil, true},
{"wut+tcp@8.8.8.8:53", nil, true},
{"2a09::", &Resolver{
Addr: "[2a09::]:53",
Protocols: []string{"udp"},
}, false},
{"[2a09::]", nil, true},
{"[2a09::]:123", &Resolver{
Addr: "[2a09::]:123",
Protocols: []string{"udp"},
}, false},
{"tcp+udp@2a09::", &Resolver{
Addr: "[2a09::]:53",
Protocols: []string{"tcp", "udp"},
}, false},
{"doh@https://doh.serv/query", &Resolver{
Addr: "https://doh.serv/query",
Protocols: []string{"doh"},
}, false},
{"doh+udp@https://doh.serv/query", nil, true},
{"https://doh.serv/query", nil, true},
{"udp@https://doh.serv/query", nil, true},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
gotR, err := ParseResolver(tt.input, false)
if (err != nil) != tt.wantErr {
t.Errorf("schemaToResolver() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotR, tt.wantR) {
t.Errorf("schemaToResolver() gotR = %v, want %v", gotR, tt.wantR)
}
})
}
}