@@ -5,10 +5,10 @@ import (
55 "testing"
66
77 "github.com/onsi/gomega"
8+ rbacv1 "k8s.io/api/rbac/v1"
89 "sigs.k8s.io/controller-tools/pkg/genall"
910 "sigs.k8s.io/controller-tools/pkg/loader"
1011 "sigs.k8s.io/controller-tools/pkg/markers"
11- rbacv1 "k8s.io/api/rbac/v1"
1212)
1313
1414func TestAdvancedFeatureGates (t * testing.T ) {
@@ -21,67 +21,67 @@ func TestAdvancedFeatureGates(t *testing.T) {
2121 // Set up generation context
2222 reg := & markers.Registry {}
2323 g .Expect (reg .Register (RuleDefinition )).To (gomega .Succeed ())
24-
24+
2525 ctx := & genall.GenerationContext {
2626 Collector : & markers.Collector {Registry : reg },
2727 Roots : pkgs ,
2828 }
2929
3030 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
3535 shouldNotContain []string
3636 }{
3737 {
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" },
4242 shouldNotContain : []string {"services" },
4343 },
4444 {
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" },
4949 shouldNotContain : []string {"services" },
5050 },
5151 {
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" },
5656 shouldNotContain : []string {},
5757 },
5858 {
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" },
6363 shouldNotContain : []string {"secrets" , "services" },
6464 },
6565 {
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" },
7070 shouldNotContain : []string {"services" },
7171 },
7272 {
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" },
7777 shouldNotContain : []string {},
7878 },
7979 }
8080
8181 for _ , tt := range tests {
8282 t .Run (tt .name , func (t * testing.T ) {
8383 g := gomega .NewWithT (t )
84-
84+
8585 objs , err := GenerateRoles (ctx , "test-role" , tt .featureGates )
8686 g .Expect (err ).NotTo (gomega .HaveOccurred ())
8787 g .Expect (objs ).To (gomega .HaveLen (1 ))
@@ -97,7 +97,7 @@ func TestAdvancedFeatureGates(t *testing.T) {
9797 }
9898
9999 for _ , resource := range tt .shouldContain {
100- g .Expect (rulesStr ).To (gomega .ContainSubstring (resource ),
100+ g .Expect (rulesStr ).To (gomega .ContainSubstring (resource ),
101101 "Expected resource %s to be present" , resource )
102102 }
103103
0 commit comments