diff options
author | 2018-02-16 11:05:52 -0500 | |
---|---|---|
committer | 2018-02-16 11:05:52 -0500 | |
commit | 9719a47c1bc0bf0098ee07fd004e4d2d2ee139d9 (patch) | |
tree | 5b9c4384aabf1dfdca1c512d098e339a883ae991 /plugin/kubernetes/setup_test.go | |
parent | 2cad04ec10584a19dae5b34434d34dedccaabd26 (diff) | |
download | coredns-9719a47c1bc0bf0098ee07fd004e4d2d2ee139d9.tar.gz coredns-9719a47c1bc0bf0098ee07fd004e4d2d2ee139d9.tar.zst coredns-9719a47c1bc0bf0098ee07fd004e4d2d2ee139d9.zip |
plugin/kubernetes: Add noendpoints option (#1536)
* add noendpoints option
* go fmt
Diffstat (limited to 'plugin/kubernetes/setup_test.go')
-rw-r--r-- | plugin/kubernetes/setup_test.go | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/plugin/kubernetes/setup_test.go b/plugin/kubernetes/setup_test.go index 0b4347ff7..3ce837e98 100644 --- a/plugin/kubernetes/setup_test.go +++ b/plugin/kubernetes/setup_test.go @@ -491,7 +491,7 @@ kubernetes cluster.local`, } } -func TestKubernetesEndpointsParse(t *testing.T) { +func TestKubernetesParseEndpointPodNames(t *testing.T) { tests := []struct { input string // Corefile data as string shouldErr bool // true if test case is exected to produce an error. @@ -553,3 +553,65 @@ func TestKubernetesEndpointsParse(t *testing.T) { } } } + +func TestKubernetesParseNoEndpoints(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 { + noendpoints +}`, + false, + "", + false, + }, + // invalid + { + `kubernetes coredns.local { + noendpoints ixnay on the endpointsay +}`, + true, + "rong argument count or unexpected", + true, + }, + // not set + { + `kubernetes coredns.local { +}`, + false, + "", + true, + }, + } + + 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 + } + + foundEndpointsInit := k8sController.opts.initEndpointsCache + if foundEndpointsInit != test.expectedEndpointsInit { + t.Errorf("Test %d: Expected kubernetes controller to be initialized with endpoints watch '%v'. Instead found endpoints watch '%v' for input '%s'", i, test.expectedEndpointsInit, foundEndpointsInit, test.input) + } + } +} |