aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/setup_test.go
diff options
context:
space:
mode:
authorGravatar darkweaver87 <remi-buisson@orange.fr> 2018-05-23 14:57:59 +0200
committerGravatar Chris O'Haver <cohaver@infoblox.com> 2018-05-23 08:57:59 -0400
commit003e104fca728b0412fae2e139c84f416acf76ae (patch)
treec8eb4004992976435d4cc4dd983cbe89179e36a7 /plugin/kubernetes/setup_test.go
parent0f74281a533a86b7b5ccaa0173d440d80d709308 (diff)
downloadcoredns-003e104fca728b0412fae2e139c84f416acf76ae.tar.gz
coredns-003e104fca728b0412fae2e139c84f416acf76ae.tar.zst
coredns-003e104fca728b0412fae2e139c84f416acf76ae.zip
ADD ignoreemptyservice option for kubernetes plugin (#1813)
* ADD: ignoreemptyservice option for kubernetes plugin * Modify documentation and rename option to add space * UPD: Add unit tests * UPD: gofmt * Add unit test for ignore emptyservice * gofmt * xfr tests failed * Rename emptyservice to empty_service
Diffstat (limited to 'plugin/kubernetes/setup_test.go')
-rw-r--r--plugin/kubernetes/setup_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/plugin/kubernetes/setup_test.go b/plugin/kubernetes/setup_test.go
index 63ea52f66..94562ce64 100644
--- a/plugin/kubernetes/setup_test.go
+++ b/plugin/kubernetes/setup_test.go
@@ -615,3 +615,73 @@ func TestKubernetesParseNoEndpoints(t *testing.T) {
}
}
}
+
+func TestKubernetesParseIgnoreEmptyService(t *testing.T) {
+ tests := []struct {
+ input string // Corefile data as string
+ shouldErr bool // true if test case is exected to produce an error.
+ expectedErrContent string // substring from the expected error. Empty for positive cases.
+ expectedEndpointsInit bool
+ }{
+ // valid
+ {
+ `kubernetes coredns.local {
+ ignore empty_service
+}`,
+ false,
+ "",
+ true,
+ },
+ // invalid
+ {
+ `kubernetes coredns.local {
+ ignore ixnay on the endpointsay
+}`,
+ true,
+ "unable to parse ignore value",
+ false,
+ },
+ {
+ `kubernetes coredns.local {
+ ignore empty_service ixnay on the endpointsay
+}`,
+ false,
+ "",
+ true,
+ },
+ // not set
+ {
+ `kubernetes coredns.local {
+}`,
+ false,
+ "",
+ false,
+ },
+ }
+
+ for i, test := range tests {
+ c := caddy.NewTestController("dns", test.input)
+ k8sController, err := kubernetesParse(c)
+
+ if test.shouldErr && err == nil {
+ t.Errorf("Test %d: Expected error, but did not find error for input '%s'. Error was: '%v'", i, test.input, err)
+ }
+
+ if err != nil {
+ if !test.shouldErr {
+ t.Errorf("Test %d: Expected no error but found one for input %s. Error was: %v", i, test.input, err)
+ continue
+ }
+
+ if !strings.Contains(err.Error(), test.expectedErrContent) {
+ t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err, test.input)
+ }
+ continue
+ }
+
+ foundIgnoreEmptyService := k8sController.opts.ignoreEmptyService
+ if foundIgnoreEmptyService != test.expectedEndpointsInit {
+ t.Errorf("Test %d: Expected kubernetes controller to be initialized with ignore empty_service '%v'. Instead found ignore empty_service watch '%v' for input '%s'", i, test.expectedEndpointsInit, foundIgnoreEmptyService, test.input)
+ }
+ }
+}