-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsetup_test.go
More file actions
68 lines (58 loc) · 1.32 KB
/
setup_test.go
File metadata and controls
68 lines (58 loc) · 1.32 KB
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
package coredns_omada
import (
"fmt"
"testing"
"github.com/coredns/caddy"
)
func TestSetup(t *testing.T) {
testServer := setupTestServer()
defer testServer.Close()
url := testServer.URL
tests := []struct {
config string
expectedError bool
}{
// valid config with mock server
{fmt.Sprintf(`omada {
controller_url %s
username test
password test
site .*
}`, url), false},
// there will be no response from the controller url
{`omada {
controller_url http://localhost
username test
password test
site .*
}`, true},
// invalid config: missing username
{`omada {
controller_url http://localhost
password test
site .*
}`, true},
// ignore connection errors to omada controller on startup
{`omada {
controller_url http://localhost:8888
username test
password test
site .*
ignore_startup_errors true
}`, false},
// do not ignore connection errors to omada controller on startup
{`omada {
controller_url http://localhost:8888
username test
password test
site .*
ignore_startup_errors false
}`, true},
}
for i, test := range tests {
caddy := caddy.NewTestController("dns", test.config)
if err := setup(caddy); (err == nil) == test.expectedError {
t.Fatalf("Unexpected errors: %v in test: %d\n\t%s", err, i, test.config)
}
}
}