diff options
author | 2019-06-17 20:20:33 +0800 | |
---|---|---|
committer | 2019-06-17 13:20:33 +0100 | |
commit | c432f894b287707707407385d679872dd5b444cb (patch) | |
tree | c7b8f56265517722f53d9526a71cd390ce5c1fd8 /plugin/bind/setup_test.go | |
parent | c1d7c2e69becba8c9dd700aea9819a4ebde2facb (diff) | |
download | coredns-c432f894b287707707407385d679872dd5b444cb.tar.gz coredns-c432f894b287707707407385d679872dd5b444cb.tar.zst coredns-c432f894b287707707407385d679872dd5b444cb.zip |
Rename bind_test.go to setup_test.go (#2891)
Signed-off-by: Xiao An <hac@zju.edu.cn>
Diffstat (limited to 'plugin/bind/setup_test.go')
-rw-r--r-- | plugin/bind/setup_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plugin/bind/setup_test.go b/plugin/bind/setup_test.go new file mode 100644 index 000000000..ede4efac0 --- /dev/null +++ b/plugin/bind/setup_test.go @@ -0,0 +1,46 @@ +package bind + +import ( + "testing" + + "github.com/coredns/coredns/core/dnsserver" + + "github.com/mholt/caddy" +) + +func TestSetup(t *testing.T) { + for i, test := range []struct { + config string + expected []string + failing bool + }{ + {`bind 1.2.3.4`, []string{"1.2.3.4"}, false}, + {`bind`, nil, true}, + {`bind 1.2.3.invalid`, nil, true}, + {`bind 1.2.3.4 ::5`, []string{"1.2.3.4", "::5"}, false}, + {`bind ::1 1.2.3.4 ::5 127.9.9.0`, []string{"::1", "1.2.3.4", "::5", "127.9.9.0"}, false}, + {`bind ::1 1.2.3.4 ::5 127.9.9.0 noone`, nil, true}, + } { + c := caddy.NewTestController("dns", test.config) + err := setup(c) + if err != nil { + if !test.failing { + t.Fatalf("Test %d, expected no errors, but got: %v", i, err) + } + continue + } + if test.failing { + t.Fatalf("Test %d, expected to failed but did not, returned values", i) + } + cfg := dnsserver.GetConfig(c) + if len(cfg.ListenHosts) != len(test.expected) { + t.Errorf("Test %d : expected the config's ListenHosts size to be %d, was %d", i, len(test.expected), len(cfg.ListenHosts)) + continue + } + for i, v := range test.expected { + if got, want := cfg.ListenHosts[i], v; got != want { + t.Errorf("Test %d : expected the config's ListenHost to be %s, was %s", i, want, got) + } + } + } +} |