-
Notifications
You must be signed in to change notification settings - Fork 11
/
namespace_test.go
72 lines (65 loc) · 1.96 KB
/
namespace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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)
}
}
}