-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup_test.go
75 lines (69 loc) · 1.86 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
package redis
import (
"testing"
"time"
"github.com/coredns/caddy"
)
func TestSetup(t *testing.T) {
const defEndpoint = "127.0.0.1:6379"
tests := []struct {
input string
shouldErr bool
expectedNttl time.Duration
expectedPttl time.Duration
expectedEndpoint string
}{
{`redis`, false, maxNTTL, maxTTL, defEndpoint},
{`redis example.nl {
success 10
}`, false, maxNTTL, 10 * time.Second, defEndpoint},
{`redis example.nl {
success 10
denial 15
}`, false, 15 * time.Second, 10 * time.Second, defEndpoint},
{`redis {
endpoint 127.0.0.2:6379
}`, false, maxNTTL, maxTTL, "127.0.0.2:6379"},
{`redis {
endpoint 127.0.0.3
}`, false, maxNTTL, maxTTL, "127.0.0.3:6379"},
// fails
{`redis example.nl {
success 15
denial aaa
}`, true, maxTTL, maxTTL, defEndpoint},
{`redis example.nl {
positive 15
negative aaa
}`, true, maxTTL, maxTTL, defEndpoint},
{`redis {
endpoint :1:1:6379
}`, true, maxTTL, maxTTL, defEndpoint},
{`redis {
endpoint 127.0.0.a
}`, true, maxTTL, maxTTL, defEndpoint},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.input)
re, err := parse(c)
if test.shouldErr && err == nil {
t.Errorf("Test %v: Expected error but found nil", i)
continue
} else if !test.shouldErr && err != nil {
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
continue
}
if test.shouldErr && err != nil {
continue
}
if re.nttl != test.expectedNttl {
t.Errorf("Test %v: Expected nttl %v but found: %v", i, test.expectedNttl, re.nttl)
}
if re.pttl != test.expectedPttl {
t.Errorf("Test %v: Expected pttl %v but found: %v", i, test.expectedPttl, re.pttl)
}
if re.addr != test.expectedEndpoint {
t.Errorf("Test %v: Expected endpoint %v but found: %v", i, test.expectedEndpoint, re.addr)
}
}
}