coredns/plugin/kubernetes/namespace_test.go
Miek Gieben 58c703f5ef
Run gofmt -w -s on codebase (#2773)
This formats and simplifies all code by running gofmt -w -s on all Go
files.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-04-08 11:13:46 +01:00

72 lines
2 KiB
Go

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)
}
}
}