aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Zou Nengren <zounengren@cmss.chinamobile.com> 2020-06-30 03:02:56 +0800
committerGravatar GitHub <noreply@github.com> 2020-06-29 12:02:56 -0700
commit54373707346b8dfc942df03c72a3d1acd34051ad (patch)
tree9b729eabe66d0db811351b1b3d1bf64776fc812c /plugin
parent877ea3e203e3a72294ffcb78c26f5b58e7abf006 (diff)
downloadcoredns-54373707346b8dfc942df03c72a3d1acd34051ad.tar.gz
coredns-54373707346b8dfc942df03c72a3d1acd34051ad.tar.zst
coredns-54373707346b8dfc942df03c72a3d1acd34051ad.zip
complete transfer plugin test case (#3967)
Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/transfer/setup_test.go54
1 files changed, 53 insertions, 1 deletions
diff --git a/plugin/transfer/setup_test.go b/plugin/transfer/setup_test.go
index 421910d46..09d8657e9 100644
--- a/plugin/transfer/setup_test.go
+++ b/plugin/transfer/setup_test.go
@@ -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)
+ }
+}