diff options
author | 2017-09-09 11:11:07 +0100 | |
---|---|---|
committer | 2017-09-09 11:11:07 +0100 | |
commit | e4170150c72d44d757e063aec0cbd573c0c77ab9 (patch) | |
tree | 930651c69d98118eb597c4293528c8718d8b442d /middleware | |
parent | 8e5d0a23fa7225382f869a6af918f1916bca352c (diff) | |
download | coredns-e4170150c72d44d757e063aec0cbd573c0c77ab9.tar.gz coredns-e4170150c72d44d757e063aec0cbd573c0c77ab9.tar.zst coredns-e4170150c72d44d757e063aec0cbd573c0c77ab9.zip |
mw/secondary: more tests in setup_test.go (#1039)
Improve the syntax tests for this middleware.
Diffstat (limited to 'middleware')
-rw-r--r-- | middleware/secondary/setup_test.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/middleware/secondary/setup_test.go b/middleware/secondary/setup_test.go index c58483f6b..bf2b203ad 100644 --- a/middleware/secondary/setup_test.go +++ b/middleware/secondary/setup_test.go @@ -6,17 +6,18 @@ import ( "github.com/mholt/caddy" ) -// TODO(miek): this only check the syntax. func TestSecondaryParse(t *testing.T) { tests := []struct { inputFileRules string shouldErr bool transferFrom string + zones []string }{ { `secondary`, false, // TODO(miek): should actually be true, because without transfer lines this does not make sense "", + nil, }, { `secondary { @@ -24,18 +25,41 @@ func TestSecondaryParse(t *testing.T) { transfer to 127.0.0.1 }`, false, - "", + "127.0.0.1:53", + nil, + }, + { + `secondary example.org { + transfer from 127.0.0.1 + transfer to 127.0.0.1 + }`, + false, + "127.0.0.1:53", + []string{"example.org."}, }, } for i, test := range tests { c := caddy.NewTestController("dns", test.inputFileRules) - _, err := secondaryParse(c) + s, err := secondaryParse(c) if err == nil && test.shouldErr { t.Fatalf("Test %d expected errors, but got no error", i) } else if err != nil && !test.shouldErr { t.Fatalf("Test %d expected no errors, but got '%v'", i, err) } + + for i, name := range test.zones { + if x := s.Names[i]; x != name { + t.Fatalf("Test %d zone names don't match expected %q, but got %q", i, name, x) + } + } + + // This is only set *iff* we have a zone (i.e. not in all tests above) + for _, v := range s.Z { + if x := v.TransferFrom[0]; x != test.transferFrom { + t.Fatalf("Test %d transform from names don't match expected %q, but got %q", i, test.transferFrom, x) + } + } } } |