-
Notifications
You must be signed in to change notification settings - Fork 318
/
namespace_test.go
48 lines (43 loc) · 1.05 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
package kube2iam
import (
"testing"
v1 "k8s.io/api/core/v1"
)
func TestGetNamespaceRoleAnnotation(t *testing.T) {
var parseTests = []struct {
test string
annotation string
expected []string
}{
{
test: "Empty string",
annotation: "",
expected: []string{},
},
{
test: "Malformed string",
annotation: "something malformed here",
expected: []string{},
},
{
test: "Single entity array",
annotation: `["test-something"]`,
expected: []string{"test-something"},
},
{
test: "Multi-element array",
annotation: `["test-something","test-another"]`,
expected: []string{"test-something", "test-another"},
},
}
for _, tt := range parseTests {
t.Run(tt.test, func(t *testing.T) {
ns := &v1.Namespace{}
ns.Annotations = map[string]string{"namespaceKey": tt.annotation}
resp := GetNamespaceRoleAnnotation(ns, "namespaceKey")
if len(resp) != len(tt.expected) {
t.Errorf("Expected resp length of [%d] but received [%d]", len(tt.expected), len(resp))
}
})
}
}