complete transfer plugin  test case
@@ -6,9 +6,16 @@ import (
"github.com/caddyserver/caddy"
)
+func newTestControllerWithZones(input string, zones []string) *caddy.Controller {
+ ctr := caddy.NewTestController("dns", input)
+ ctr.ServerBlockKeys = append(ctr.ServerBlockKeys, zones...)
+ return ctr
+}
+
func TestParse(t *testing.T) {
tests := []struct {
input string
+ zones []string
shouldErr bool
exp *Transfer
}{
@@ -18,6 +25,7 @@ func TestParse(t *testing.T) {
transfer example.com example.edu {
to * 1.2.3.4
}`,
+ nil,
false,
&Transfer{
xfrs: []*xfr{{
@@ -32,18 +40,42 @@ func TestParse(t *testing.T) {
// errors
{`transfer example.net example.org {
}`,
+ nil,
true,
nil,
},
{`transfer example.net example.org {
invalid option
}`,
+ nil,
true,
nil,
},
+ {
+ `
+ transfer example.com example.edu {
+ to example.com 1.2.3.4
+ }`,
+ nil,
+ true,
+ nil,
+ },
+ {
+ `transfer {
+ to 1.2.3.4 5.6.7.8:1053 [1::2]:34
+ }`,
+ []string{"."},
+ false,
+ &Transfer{
+ xfrs: []*xfr{{
+ Zones: []string{"."},
+ to: []string{"1.2.3.4:53", "5.6.7.8:1053", "[1::2]:34"},
+ }},
+ },
+ },
}
for i, tc := range tests {
- c := caddy.NewTestController("dns", tc.input)
+ c := newTestControllerWithZones(tc.input, tc.zones)
transfer, err := parse(c)
if err == nil && tc.shouldErr {
@@ -52,6 +84,9 @@ func TestParse(t *testing.T) {
if err != nil && !tc.shouldErr {
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
}
+ if tc.exp == nil && transfer != nil {
+ t.Fatalf("Test %d expected %v xfrs, got %#v", i, tc.exp, transfer)
+ }
if tc.shouldErr {
continue
}
@@ -83,3 +118,20 @@ func TestParse(t *testing.T) {
}
}
}
+
+func TestSetup(t *testing.T) {
+ c := caddy.NewTestController("dns", "transfer")
+ if err := setup(c); err == nil {
+ t.Fatal("Expected errors, but got nil")
+ }
+
+ c = caddy.NewTestController("dns", `transfer example.net example.org {
+ to 1.2.3.4 5.6.7.8:1053 [1::2]:34
+ }
+ transfer example.com example.edu {
+ to * 1.2.3.4
+ }`)
+ if err := setup(c); err != nil {
+ t.Fatalf("Expected no errors, but got %v", err)
+ }
+}
