@@ -5,10 +5,10 @@ import (
5
5
"testing"
6
6
7
7
"github.com/onsi/gomega"
8
+ rbacv1 "k8s.io/api/rbac/v1"
8
9
"sigs.k8s.io/controller-tools/pkg/genall"
9
10
"sigs.k8s.io/controller-tools/pkg/loader"
10
11
"sigs.k8s.io/controller-tools/pkg/markers"
11
- rbacv1 "k8s.io/api/rbac/v1"
12
12
)
13
13
14
14
func TestAdvancedFeatureGates (t * testing.T ) {
@@ -21,67 +21,67 @@ func TestAdvancedFeatureGates(t *testing.T) {
21
21
// Set up generation context
22
22
reg := & markers.Registry {}
23
23
g .Expect (reg .Register (RuleDefinition )).To (gomega .Succeed ())
24
-
24
+
25
25
ctx := & genall.GenerationContext {
26
26
Collector : & markers.Collector {Registry : reg },
27
27
Roots : pkgs ,
28
28
}
29
29
30
30
tests := []struct {
31
- name string
32
- featureGates string
33
- expectedRules int
34
- shouldContain []string
31
+ name string
32
+ featureGates string
33
+ expectedRules int
34
+ shouldContain []string
35
35
shouldNotContain []string
36
36
}{
37
37
{
38
- name : "OR logic - alpha enabled" ,
39
- featureGates : "alpha=true,beta=false" ,
40
- expectedRules : 3 , // always-on + OR rule (alpha|beta)
41
- shouldContain : []string {"pods" , "configmaps" , "secrets" },
38
+ name : "OR logic - alpha enabled" ,
39
+ featureGates : "alpha=true,beta=false" ,
40
+ expectedRules : 3 , // always-on + OR rule (alpha|beta)
41
+ shouldContain : []string {"pods" , "configmaps" , "secrets" },
42
42
shouldNotContain : []string {"services" },
43
43
},
44
44
{
45
- name : "OR logic - beta enabled" ,
46
- featureGates : "alpha=false,beta=true" ,
47
- expectedRules : 3 , // always-on + OR rule (alpha|beta)
48
- shouldContain : []string {"pods" , "configmaps" , "secrets" },
45
+ name : "OR logic - beta enabled" ,
46
+ featureGates : "alpha=false,beta=true" ,
47
+ expectedRules : 3 , // always-on + OR rule (alpha|beta)
48
+ shouldContain : []string {"pods" , "configmaps" , "secrets" },
49
49
shouldNotContain : []string {"services" },
50
50
},
51
51
{
52
- name : "OR logic - both enabled" ,
53
- featureGates : "alpha=true,beta=true" ,
54
- expectedRules : 4 , // always-on + OR rule + AND rule
55
- shouldContain : []string {"pods" , "configmaps" , "secrets" , "services" },
52
+ name : "OR logic - both enabled" ,
53
+ featureGates : "alpha=true,beta=true" ,
54
+ expectedRules : 4 , // always-on + OR rule + AND rule
55
+ shouldContain : []string {"pods" , "configmaps" , "secrets" , "services" },
56
56
shouldNotContain : []string {},
57
57
},
58
58
{
59
- name : "OR logic - neither enabled" ,
60
- featureGates : "alpha=false,beta=false" ,
61
- expectedRules : 2 , // only always-on
62
- shouldContain : []string {"pods" , "configmaps" },
59
+ name : "OR logic - neither enabled" ,
60
+ featureGates : "alpha=false,beta=false" ,
61
+ expectedRules : 2 , // only always-on
62
+ shouldContain : []string {"pods" , "configmaps" },
63
63
shouldNotContain : []string {"secrets" , "services" },
64
64
},
65
65
{
66
- name : "AND logic - only alpha enabled" ,
67
- featureGates : "alpha=true,beta=false" ,
68
- expectedRules : 3 , // always-on + OR rule (alpha|beta)
69
- shouldContain : []string {"pods" , "configmaps" , "secrets" },
66
+ name : "AND logic - only alpha enabled" ,
67
+ featureGates : "alpha=true,beta=false" ,
68
+ expectedRules : 3 , // always-on + OR rule (alpha|beta)
69
+ shouldContain : []string {"pods" , "configmaps" , "secrets" },
70
70
shouldNotContain : []string {"services" },
71
71
},
72
72
{
73
- name : "AND logic - both enabled" ,
74
- featureGates : "alpha=true,beta=true" ,
75
- expectedRules : 4 , // always-on + OR rule + AND rule
76
- shouldContain : []string {"pods" , "configmaps" , "secrets" , "services" },
73
+ name : "AND logic - both enabled" ,
74
+ featureGates : "alpha=true,beta=true" ,
75
+ expectedRules : 4 , // always-on + OR rule + AND rule
76
+ shouldContain : []string {"pods" , "configmaps" , "secrets" , "services" },
77
77
shouldNotContain : []string {},
78
78
},
79
79
}
80
80
81
81
for _ , tt := range tests {
82
82
t .Run (tt .name , func (t * testing.T ) {
83
83
g := gomega .NewWithT (t )
84
-
84
+
85
85
objs , err := GenerateRoles (ctx , "test-role" , tt .featureGates )
86
86
g .Expect (err ).NotTo (gomega .HaveOccurred ())
87
87
g .Expect (objs ).To (gomega .HaveLen (1 ))
@@ -97,7 +97,7 @@ func TestAdvancedFeatureGates(t *testing.T) {
97
97
}
98
98
99
99
for _ , resource := range tt .shouldContain {
100
- g .Expect (rulesStr ).To (gomega .ContainSubstring (resource ),
100
+ g .Expect (rulesStr ).To (gomega .ContainSubstring (resource ),
101
101
"Expected resource %s to be present" , resource )
102
102
}
103
103
0 commit comments