diff options
author | 2017-11-08 08:07:10 -0500 | |
---|---|---|
committer | 2017-11-08 08:07:10 -0500 | |
commit | 3527be6c0056acbcd8dc9848ff96be2136c68ed5 (patch) | |
tree | cb03011fb882955cf67c726d6c3cc78f84451968 /plugin/kubernetes/setup_test.go | |
parent | c6ce769fc64f00d1fd0d34914a9bb5f4de2f7c2c (diff) | |
download | coredns-3527be6c0056acbcd8dc9848ff96be2136c68ed5.tar.gz coredns-3527be6c0056acbcd8dc9848ff96be2136c68ed5.tar.zst coredns-3527be6c0056acbcd8dc9848ff96be2136c68ed5.zip |
Add option to use pod name rather than IP address for Kubernetes (#1190)
Change to use a new 'endpoints' directive and use a constant
Add initial docs for 'endpoints' directive
Add tests to Kubernetes setup for endpoints
Changes based on PR feedback
endpoint_pod_names is a boolean config option. Chahanged docs to reflect this.
Add a test when endpoints_pod_names is not set
Update README.md
Remove endpointNameModeName as it is no longer used
Diffstat (limited to 'plugin/kubernetes/setup_test.go')
-rw-r--r-- | plugin/kubernetes/setup_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/plugin/kubernetes/setup_test.go b/plugin/kubernetes/setup_test.go index 3f15ead06..224c168a1 100644 --- a/plugin/kubernetes/setup_test.go +++ b/plugin/kubernetes/setup_test.go @@ -471,3 +471,66 @@ func TestKubernetesParse(t *testing.T) { } } } + +func TestKubernetesEndpointsParse(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. + expectedEndpointMode bool + }{ + // valid endpoints mode + { + `kubernetes coredns.local { + endpoint_pod_names +}`, + false, + "", + true, + }, + // endpoints invalid + { + `kubernetes coredns.local { + endpoint_pod_names giant_seed +}`, + true, + "rong argument count or unexpected", + false, + }, + // endpoint 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 + } + + // Endpoints + foundEndpointNameMode := k8sController.endpointNameMode + if foundEndpointNameMode != test.expectedEndpointMode { + t.Errorf("Test %d: Expected kubernetes controller to be initialized with endpoints mode '%v'. Instead found endpoints mode '%v' for input '%s'", i, test.expectedEndpointMode, foundEndpointNameMode, test.input) + } + } +} |