-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuser_test.go
70 lines (62 loc) · 1.43 KB
/
user_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
package main
import (
"testing"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestCreateUserNamesInGroups(t *testing.T) {
var (
ul UserList
rolebindings = &v1.ConfigMapList{
Items: []v1.ConfigMap{
{
ObjectMeta: metav1.ObjectMeta{
Name: "rolebinding1",
Labels: map[string]string{
"gocat.zaim.net/configmap-type": "rolebinding",
},
},
Data: map[string]string{
"Developer": "user1\nuser2\n",
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "rolebinding2",
Labels: map[string]string{
"gocat.zaim.net/configmap-type": "rolebinding",
},
},
Data: map[string]string{
"Admin": "user3\nuser4",
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "rolebinding3",
Labels: map[string]string{
"gocat.zaim.net/configmap-type": "rolebinding",
},
},
Data: map[string]string{
"Developer": "user5",
"Admin": "user6",
},
},
},
}
)
userNamesInGroups := ul.createUserNamesInGroups(rolebindings)
if len(userNamesInGroups) != 2 {
t.Fatalf("userNamesInGroups length is not 2")
}
require.Equal(t,
map[string]struct{}{"user1": {}, "user2": {}, "user5": {}},
userNamesInGroups[RoleDeveloper],
)
require.Equal(t,
map[string]struct{}{"user3": {}, "user4": {}, "user6": {}},
userNamesInGroups[RoleAdmin],
)
}