-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_test.go
84 lines (70 loc) · 2.1 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
package recursor
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
"github.com/coredns/caddy"
)
// Tests the various setups
func TestSetup_controller_should_work_with_full_example_config(t *testing.T) {
filePath := "examples/config1.caddy"
fileBytes, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("read config file %s error, %v", filePath, err)
}
c := caddy.NewTestController("dns", string(fileBytes))
if err := setup(c); err != nil {
t.Fatalf("Expected no errors, but got: %v", err)
}
}
func TestSetup_controller_should_work_with_minimal_config(t *testing.T) {
c := caddy.NewTestController("dns", pluginName+" ")
assert.Nil(t, setup(c), "empty config")
c = caddy.NewTestController("dns", pluginName+" {\n}")
assert.Nil(t, setup(c), "empty config")
c = caddy.NewTestController("dns", pluginName+" {\nverbose 0\n}")
assert.Nil(t, setup(c), "empty config")
}
func TestSetup_controller_should_fail_with_incorrect_config(t *testing.T) {
c := caddy.NewTestController("dns", pluginName+` {
resolver incorrect {
}
}`)
assert.Error(t, setup(c), "incorrect resolver config")
c = caddy.NewTestController("dns", pluginName+` {
resolver incorrect {
urls
}
}`)
assert.Error(t, setup(c), "incorrect resolver config")
c = caddy.NewTestController("dns", pluginName+` {
alias incorrect {
}
}`)
assert.Error(t, setup(c), "incorrect alias config")
c = caddy.NewTestController("dns", pluginName+` {
alias incorrect {
ips
}
}`)
assert.Error(t, setup(c), "wrong alias config")
}
func TestSetup_controller_should_work_with_wildcard_config(t *testing.T) {
c := caddy.NewTestController("dns", pluginName+` {
alias * {
}
}`)
assert.Nil(t, setup(c), "wildcard aliases don't need hosts or ips")
c = caddy.NewTestController("dns", pluginName+` {
alias * {
ips 1.1.1.1
hosts www.example.org
}
}`)
assert.Nil(t, setup(c), "wildcard aliases accept hosts and ips")
c = caddy.NewTestController("dns", pluginName+` {
alias not-wildcard {
}
}`)
assert.Error(t, setup(c), "not-wildcard aliases should have ips or hosts defined")
}