-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
108 lines (99 loc) · 1.65 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
package drovedns
import (
"testing"
"github.com/coredns/caddy"
"github.com/stretchr/testify/assert"
)
// TestSetup tests the various things that should be parsed by setup.
// Make sure you also test for parse errors.
func TestSetup(t *testing.T) {
tests := []struct {
config string
error bool
message string
}{
{
`drove {
endpoint http://url.random
access_token "O-Bearer token"
}`,
false,
"Valid config",
},
{
`drove {
endpoint http://url.random
user_pass user pass
}`,
false,
"Valid config",
},
{
`drove {
endpoint http://url.random 8080
access_token token
}`,
true,
"Invalid endpoint",
},
{
`drove {
endpoint http://url.random
access_token O-Bearer token
}`,
true,
"Invalid Access token",
},
{
`drove {
endpoint http://url.random
user_pass user:blah
}`,
true,
"User pass should be space delimited",
},
{
`drove {
access_token token
}`,
true,
"Missing endpoint",
},
{
`drove {
endpoint http://url.random
access_token token
user_pass user blah
}`,
true,
"Access TOken and user_pass cant be added",
},
{
`drove {
endpoint http://url.random
access_token token
blaharg
}`,
true,
"Random arg cannot be added",
},
{
`drove {
endpoint http://url.random
access_token token
blaharg
}`,
true,
"Empty Stanza is invalid",
},
}
for _, tt := range tests {
c := caddy.NewTestController("drovedns", tt.config)
_, err := parseAndCreate(c)
if tt.error {
assert.Error(t, err, tt.message)
} else {
assert.NoError(t, err, tt.message)
}
}
}