aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/parse/parse_test.go
diff options
context:
space:
mode:
authorGravatar Brad Beam <bradbeam@users.noreply.github.com> 2017-12-13 10:18:08 -0600
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2017-12-13 11:18:08 -0500
commit556a289d9a2ec04583b26c89712000aac578ae89 (patch)
treef62d4d7655f69c06cc1e64a52a0ba6cb293a02d9 /plugin/pkg/parse/parse_test.go
parenta469a17cdfccfb435f819ebdf7ff7b43b207c8b4 (diff)
downloadcoredns-556a289d9a2ec04583b26c89712000aac578ae89.tar.gz
coredns-556a289d9a2ec04583b26c89712000aac578ae89.tar.zst
coredns-556a289d9a2ec04583b26c89712000aac578ae89.zip
Moving TransferParse from file to its own package (#1286)
* Moving TransferParse from file to its own package * Adding tests for parse
Diffstat (limited to 'plugin/pkg/parse/parse_test.go')
-rw-r--r--plugin/pkg/parse/parse_test.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/plugin/pkg/parse/parse_test.go b/plugin/pkg/parse/parse_test.go
new file mode 100644
index 000000000..b1aa3730f
--- /dev/null
+++ b/plugin/pkg/parse/parse_test.go
@@ -0,0 +1,92 @@
+package parse
+
+import (
+ "testing"
+
+ "github.com/mholt/caddy"
+)
+
+func TestTransfer(t *testing.T) {
+ tests := []struct {
+ inputFileRules string
+ shouldErr bool
+ secondary bool
+ expectedTo []string
+ expectedFrom []string
+ }{
+ // OK transfer to
+ {
+ `to 127.0.0.1`,
+ false, false, []string{"127.0.0.1:53"}, []string{},
+ },
+ // OK transfer tos
+ {
+ `to 127.0.0.1 127.0.0.2`,
+ false, false, []string{"127.0.0.1:53", "127.0.0.2:53"}, []string{},
+ },
+ // OK transfer from
+ {
+ `from 127.0.0.1`,
+ false, true, []string{}, []string{"127.0.0.1:53"},
+ },
+ // OK transfer froms
+ {
+ `from 127.0.0.1 127.0.0.2`,
+ false, true, []string{}, []string{"127.0.0.1:53", "127.0.0.2:53"},
+ },
+ // OK transfer tos/froms
+ {
+ `to 127.0.0.1 127.0.0.2
+ from 127.0.0.1 127.0.0.2`,
+ false, true, []string{"127.0.0.1:53", "127.0.0.2:53"}, []string{"127.0.0.1:53", "127.0.0.2:53"},
+ },
+ // Bad transfer from, secondary false
+ {
+ `from 127.0.0.1`,
+ true, false, []string{}, []string{},
+ },
+ // Bad transfer from garbage
+ {
+ `from !@#$%^&*()`,
+ true, true, []string{}, []string{},
+ },
+ // Bad transfer from no args
+ {
+ `from`,
+ true, false, []string{}, []string{},
+ },
+ // Bad transfer from *
+ {
+ `from *`,
+ true, true, []string{}, []string{},
+ },
+ }
+
+ for i, test := range tests {
+ c := caddy.NewTestController("dns", test.inputFileRules)
+ tos, froms, err := Transfer(c, test.secondary)
+
+ if err == nil && test.shouldErr {
+ t.Fatalf("Test %d expected errors, but got no error %+v %+v", i, err, test)
+ } else if err != nil && !test.shouldErr {
+ t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
+ }
+
+ if test.expectedTo != nil {
+ for j, got := range tos {
+ if got != test.expectedTo[j] {
+ t.Fatalf("Test %d expected %v, got %v", i, test.expectedTo[j], got)
+ }
+ }
+ }
+ if test.expectedFrom != nil {
+ for j, got := range froms {
+ if got != test.expectedFrom[j] {
+ t.Fatalf("Test %d expected %v, got %v", i, test.expectedFrom[j], got)
+ }
+ }
+ }
+
+ }
+
+}