diff options
author | 2017-08-18 14:45:20 +0100 | |
---|---|---|
committer | 2017-08-18 14:45:20 +0100 | |
commit | f96cf27193032120ba727316c4057dffed0cbe48 (patch) | |
tree | c76caa111aba281560a3b7db91953e307c06f1c9 /middleware/federation/setup_test.go | |
parent | cc4e4a0626bf8881e2ae8b2c1e52e09c6308e74e (diff) | |
download | coredns-f96cf27193032120ba727316c4057dffed0cbe48.tar.gz coredns-f96cf27193032120ba727316c4057dffed0cbe48.tar.zst coredns-f96cf27193032120ba727316c4057dffed0cbe48.zip |
mw/federation: add federation back as separate mw for k8s (#929)
* mw/federaration
This PR add the federation back as a middleware to keep it more
contained from the main kubernetes code.
It also makes parseRequest less import and pushes this functionlity down
in the k.Entries. This minimizes (or tries to) the importance for the
qtype in the query. In the end the qtype checking should only happen
in ServeDNS - but for k8s this might proof difficult.
Numerous other cleanup in code and kubernetes tests.
* up test coverage
Diffstat (limited to 'middleware/federation/setup_test.go')
-rw-r--r-- | middleware/federation/setup_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/middleware/federation/setup_test.go b/middleware/federation/setup_test.go new file mode 100644 index 000000000..b0d09419a --- /dev/null +++ b/middleware/federation/setup_test.go @@ -0,0 +1,60 @@ +package federation + +import ( + "testing" + + "github.com/mholt/caddy" +) + +func TestSetup(t *testing.T) { + tests := []struct { + input string + shouldErr bool + expectedLen int + expectedNameZone []string // contains only entry for now + }{ + {`federation { + prod prod.example.org + }`, false, 1, []string{"prod", "prod.example.org."}}, + + {`federation { + staging staging.example.org + prod prod.example.org + }`, false, 2, []string{"prod", "prod.example.org."}}, + {`federation { + staging staging.example.org + prod prod.example.org + }`, false, 2, []string{"staging", "staging.example.org."}}, + // errors + {`federation { + }`, true, 0, []string{}}, + {`federation { + staging + }`, true, 0, []string{}}, + } + for i, test := range tests { + c := caddy.NewTestController("dns", test.input) + fed, err := federationParse(c) + if test.shouldErr && err == nil { + t.Errorf("Test %v: Expected error but found nil", i) + continue + } else if !test.shouldErr && err != nil { + t.Errorf("Test %v: Expected no error but found error: %v", i, err) + continue + } + if test.shouldErr && err != nil { + continue + } + + if x := len(fed.f); x != test.expectedLen { + t.Errorf("Test %v: Expected map length of %d, got: %d", i, test.expectedLen, x) + } + if x, ok := fed.f[test.expectedNameZone[0]]; !ok { + t.Errorf("Test %v: Expected name for %s, got nothing", i, test.expectedNameZone[0]) + } else { + if x != test.expectedNameZone[1] { + t.Errorf("Test %v: Expected zone: %s, got %s", i, test.expectedNameZone[1], x) + } + } + } +} |