-
Notifications
You must be signed in to change notification settings - Fork 7
/
labelstore_test.go
83 lines (78 loc) · 1.61 KB
/
labelstore_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
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetLabelsCM(t *testing.T) {
cmh := ConfigMapHandler{
labels: map[string]map[string]bool{
"user1": {"u1": true, "u2": true},
"user2": {"u3": true, "u4": true},
"group1": {"g1": true, "g2": true},
"group2": {"g3": true, "g4": true},
"adminGroup": {"#cluster-wide": true, "g4": true},
},
}
cases := []struct {
name string
username string
groups []string
expected map[string]bool
skip bool
}{
{
name: "User with groups",
username: "user1",
groups: []string{"group1", "group2"},
expected: map[string]bool{
"u1": true,
"u2": true,
"g1": true,
"g2": true,
"g3": true,
"g4": true,
},
},
{
name: "User without groups",
username: "user2",
groups: []string{},
expected: map[string]bool{
"u3": true,
"u4": true,
},
},
{
name: "Non-existent user",
username: "user3",
groups: []string{"group1"},
expected: map[string]bool{
"g1": true,
"g2": true,
},
},
{
name: "Non-existent group",
username: "user1",
groups: []string{"group3"},
expected: map[string]bool{
"u1": true,
"u2": true,
},
},
{
name: "admin_group",
username: "blubb",
groups: []string{"adminGroup"},
expected: nil,
skip: true,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
labels, skip := cmh.GetLabels(OAuthToken{PreferredUsername: tc.username, Groups: tc.groups})
assert.Equal(t, tc.expected, labels)
assert.Equal(t, tc.skip, skip)
})
}
}