@@ -14,15 +14,14 @@ import (
14
14
func TestGenerateRBAC (t * testing.T ) {
15
15
// Use these test cases to check if Generate function is correct
16
16
testCases := []struct {
17
- // expectedClusterRoles is the collection of ClusterRole
17
+ expectedClusterRoles []rbac. ClusterRole
18
18
expectedClusterRoleBindings []rbac.ClusterRoleBinding
19
19
dataGatherers []agent.DataGatherer
20
20
description string
21
21
}{
22
22
{
23
23
description : "Generate RBAC struct for pods datagatherer" ,
24
24
dataGatherers : []agent.DataGatherer {
25
-
26
25
{
27
26
Name : "k8s/secrets" ,
28
27
Kind : "k8s-dynamic" ,
@@ -34,6 +33,24 @@ func TestGenerateRBAC(t *testing.T) {
34
33
},
35
34
},
36
35
},
36
+ expectedClusterRoles : []rbac.ClusterRole {
37
+ {
38
+ TypeMeta : metav1.TypeMeta {
39
+ Kind : "ClusterRole" ,
40
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
41
+ },
42
+ ObjectMeta : metav1.ObjectMeta {
43
+ Name : "jetstack-secure-agent-secrets-reader" ,
44
+ },
45
+ Rules : []rbac.PolicyRule {
46
+ {
47
+ Verbs : []string {"get" , "list" , "watch" },
48
+ APIGroups : []string {"" },
49
+ Resources : []string {"secrets" },
50
+ },
51
+ },
52
+ },
53
+ },
37
54
expectedClusterRoleBindings : []rbac.ClusterRoleBinding {
38
55
{
39
56
TypeMeta : metav1.TypeMeta {
@@ -62,9 +79,10 @@ func TestGenerateRBAC(t *testing.T) {
62
79
}
63
80
64
81
for _ , input := range testCases {
65
- got := GenerateRoles (input .dataGatherers )
66
- toBeTest := GenerateBindings ( got )
82
+ gotClusterRoles := GenerateClusterRoles (input .dataGatherers )
83
+ gotClusterRoleBindings := GenerateClusterRoleBindings ( gotClusterRoles )
67
84
68
- td .Cmp (t , input .expectedClusterRoleBindings , toBeTest )
85
+ td .Cmp (t , input .expectedClusterRoleBindings , gotClusterRoleBindings )
86
+ td .Cmp (t , input .expectedClusterRoles , gotClusterRoles )
69
87
}
70
88
}
0 commit comments