aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/namespace_test.go
diff options
context:
space:
mode:
authorGravatar Matt Greenfield <matt.greenfield@datadoghq.com> 2019-03-22 08:32:40 -0600
committerGravatar Miek Gieben <miek@miek.nl> 2019-03-22 14:32:40 +0000
commita3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d (patch)
tree4d0ca8491e0340e22aa8b3631040c92fbd071cc5 /plugin/kubernetes/namespace_test.go
parent43c3e0ab68fc103967bfb9bec0363d42a5964dac (diff)
downloadcoredns-a3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d.tar.gz
coredns-a3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d.tar.zst
coredns-a3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d.zip
Add `namespace_labels` configuration for kubernetes plugin (#2707)
Diffstat (limited to 'plugin/kubernetes/namespace_test.go')
-rw-r--r--plugin/kubernetes/namespace_test.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/plugin/kubernetes/namespace_test.go b/plugin/kubernetes/namespace_test.go
new file mode 100644
index 000000000..d7d2cbcce
--- /dev/null
+++ b/plugin/kubernetes/namespace_test.go
@@ -0,0 +1,72 @@
+package kubernetes
+
+import (
+ "testing"
+)
+
+func TestFilteredNamespaceExists(t *testing.T) {
+ tests := []struct{
+ expected bool
+ kubernetesNamespaces map[string]struct{}
+ testNamespace string
+ }{
+ {true, map[string]struct{}{}, "foobar" },
+ {false, map[string]struct{}{}, "nsnoexist" },
+ }
+
+ k := Kubernetes{}
+ k.APIConn = &APIConnServeTest{}
+ for i, test := range tests {
+ k.Namespaces = test.kubernetesNamespaces
+ actual := k.filteredNamespaceExists(test.testNamespace)
+ if actual != test.expected {
+ t.Errorf("Test %d failed. Filtered namespace %s was expected to exist", i, test.testNamespace)
+ }
+ }
+}
+
+func TestNamespaceExposed(t *testing.T) {
+ tests := []struct{
+ expected bool
+ kubernetesNamespaces map[string]struct{}
+ testNamespace string
+ }{
+ {true, map[string]struct{}{ "foobar": {} }, "foobar" },
+ {false, map[string]struct{}{ "foobar": {} }, "nsnoexist" },
+ {true, map[string]struct{}{}, "foobar" },
+ {true, map[string]struct{}{}, "nsnoexist" },
+ }
+
+ k := Kubernetes{}
+ k.APIConn = &APIConnServeTest{}
+ for i, test := range tests {
+ k.Namespaces = test.kubernetesNamespaces
+ actual := k.configuredNamespace(test.testNamespace)
+ if actual != test.expected {
+ t.Errorf("Test %d failed. Namespace %s was expected to be exposed", i, test.testNamespace)
+ }
+ }
+}
+
+func TestNamespaceValid(t *testing.T) {
+ tests := []struct{
+ expected bool
+ kubernetesNamespaces map[string]struct{}
+ testNamespace string
+ }{
+ {true, map[string]struct{}{ "foobar": {} }, "foobar" },
+ {false, map[string]struct{}{ "foobar": {} }, "nsnoexist" },
+ {true, map[string]struct{}{}, "foobar" },
+ {false, map[string]struct{}{}, "nsnoexist" },
+ }
+
+ k := Kubernetes{}
+ k.APIConn = &APIConnServeTest{}
+ for i, test := range tests {
+ k.Namespaces = test.kubernetesNamespaces
+ actual := k.namespaceExposed(test.testNamespace)
+ if actual != test.expected {
+ t.Errorf("Test %d failed. Namespace %s was expected to be valid", i, test.testNamespace)
+ }
+ }
+}