forked from relekang/coredns-blocklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_test.go
61 lines (50 loc) · 1.4 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
package blocklist
import (
"testing"
"github.com/coredns/caddy"
"github.com/stretchr/testify/assert"
)
func TestSetupInvalidConfig(t *testing.T) {
c := caddy.NewTestController("dns", `blocklist`)
err := setup(c)
assert.EqualError(
t,
err,
"plugin/blocklist: Missing url or path to blocklist.",
)
c = caddy.NewTestController("dns", `blocklist example/blocklist.txt example/blocklist.txt`)
err = setup(c)
assert.EqualError(
t,
err,
"plugin/blocklist: To many arguments for blocklist.",
)
}
func TestSetupAllowlistWithNoLocation(t *testing.T) {
cfg := `blocklist https://mirror1.malwaredomains.com/files/justdomains {
allowlist
}`
c := caddy.NewTestController("dns", cfg)
err := setup(c)
assert.EqualError(
t,
err,
"plugin/blocklist: allowlist requires a single argument.",
)
}
func TestSetupValidConfigWithAllowlist(t *testing.T) {
cfg := `blocklist https://mirror1.malwaredomains.com/files/justdomains {
allowlist example/allowlist.txt
}`
c := caddy.NewTestController("dns", cfg)
err := setup(c)
assert.NoError(t, err)
}
func TestSetupValidConfig(t *testing.T) {
c := caddy.NewTestController("dns", `blocklist example/blocklist.txt`)
err := setup(c)
assert.NoError(t, err)
c = caddy.NewTestController("dns", `blocklist https://mirror1.malwaredomains.com/files/justdomains { domain_metrics }`)
err = setup(c)
assert.NoError(t, err)
}