-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathoptions_test.go
121 lines (112 loc) · 2.01 KB
/
options_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
package dnsp_test
import (
"testing"
"time"
"github.com/gophergala/dnsp"
)
func TestValidate(t *testing.T) {
var testCases = []struct {
inputOptions dnsp.Options
wantErr bool
}{
{
// invalid Net
dnsp.Options{
Net: "something invalid",
},
true,
},
{
// valid bind
dnsp.Options{
Bind: "example.com:dns",
},
false,
},
{
// invalid resolve
dnsp.Options{
Resolve: []string{
"something.com",
},
},
true,
},
{
// valid resolve
dnsp.Options{
Resolve: []string{
"0.0.0.0:53",
},
},
false,
},
{
// Poll too short
dnsp.Options{
Poll: time.Millisecond * 900,
},
true,
},
{
// whitelist and blacklist together
dnsp.Options{
Whitelist: "wikipedia.com",
Blacklist: "badsite.com",
},
true,
},
{
// invalid whitelist
dnsp.Options{
Whitelist: "somethinginvalid",
},
true,
},
{
// invalid blacklist
dnsp.Options{
Blacklist: "somethinginvalid",
},
true,
},
}
for _, tt := range testCases {
err := tt.inputOptions.Validate()
// if we expect an error and there isn't one
if tt.wantErr && err == nil {
t.Errorf("expected an error, but err is nil")
}
// if we don't expect an error and there is one
if !tt.wantErr && err != nil {
t.Errorf("expected error to be nil, but err is: %q", err)
}
}
}
func TestPathOrURL(t *testing.T) {
var testCases = []struct {
inputPath string
wantString string
wantErr bool
}{
{
"//userinfo@host/path.com",
"//userinfo@host/path.com",
false,
},
}
for _, tt := range testCases {
str, err := dnsp.PathOrURL(tt.inputPath)
if str != tt.wantString {
t.Errorf("wanted %q but got %q", tt.wantString, str)
}
// if we expect an error and there isn't one
if tt.wantErr && err == nil {
t.Errorf("expected an error, but err is nil")
}
// if we don't expect an error and there is one
if !tt.wantErr && err != nil {
t.Errorf("expected error to be nil, but err is: %q", err)
}
}
}