@@ -230,6 +230,8 @@ func createCustomRule(ctx context.Context, t *testing.T, client dynclient.Client
230230 },
231231 Spec : complianceoperatorv1.CustomRuleSpec {
232232 RulePayload : complianceoperatorv1.RulePayload {
233+ // CO recommendation: set metadata.name and spec.rulePayload.id
234+ // to the same DNS-friendly value (lowercase, hyphens, no underscores).
233235 ID : name ,
234236 Title : "ConfigMap has e2e marker" ,
235237 Description : "Checks for a ConfigMap with an e2e-marker data key" ,
@@ -321,7 +323,7 @@ func waitUntilTPInCentralDB(ctx context.Context, t *testing.T,
321323 }
322324 }
323325 require .Failf (c , "TP not yet in Central DB" , "profile %q not found" , name )
324- }, 10 * time .Second , 1 * time .Second )
326+ }, 1 * time .Minute , 2 * time .Second )
325327 return profile
326328}
327329
@@ -1031,49 +1033,35 @@ func TestComplianceV2TailoredProfileVariants(t *testing.T) {
10311033 crName := testID + "-cr"
10321034 createCustomRule (ctx , t , dynClient , crName )
10331035
1034- variants := map [string ]struct {
1035- spec complianceoperatorv1.TailoredProfileSpec
1036- expectRules []string
1037- rejectRules []string
1038- }{
1036+ variants := map [string ]complianceoperatorv1.TailoredProfileSpec {
10391037 "extends" : {
1040- spec : complianceoperatorv1.TailoredProfileSpec {
1041- Extends : "ocp4-cis" ,
1042- Title : "E2E Extends Base" ,
1043- Description : "TP extending ocp4-cis for e2e testing" ,
1044- EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1045- {Name : "ocp4-api-server-encryption-provider-config" , Rationale : "e2e test" },
1046- },
1047- DisableRules : []complianceoperatorv1.RuleReferenceSpec {
1048- {Name : "ocp4-api-server-encryption-provider-cipher" , Rationale : "e2e test" },
1049- },
1038+ Extends : "ocp4-cis" ,
1039+ Title : "E2E Extends Base" ,
1040+ Description : "TP extending ocp4-cis for e2e testing" ,
1041+ EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1042+ {Name : "ocp4-api-server-admission-control-plugin-alwaysadmit" , Rationale : "e2e test" },
1043+ },
1044+ DisableRules : []complianceoperatorv1.RuleReferenceSpec {
1045+ {Name : "ocp4-api-server-encryption-provider-cipher" , Rationale : "e2e test" },
10501046 },
1051- expectRules : []string {"ocp4-api-server-encryption-provider-config" },
1052- rejectRules : []string {"ocp4-api-server-encryption-provider-cipher" },
10531047 },
10541048 "custom-rules" : {
1055- spec : complianceoperatorv1.TailoredProfileSpec {
1056- Title : "E2E Custom Rules" ,
1057- Description : "From-scratch TP with a custom rule" ,
1058- EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1059- {Name : crName , Kind : complianceoperatorv1 .CustomRuleKind , Rationale : "e2e test" },
1060- },
1049+ Title : "E2E Custom Rules" ,
1050+ Description : "From-scratch TP with a custom rule" ,
1051+ EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1052+ {Name : crName , Kind : complianceoperatorv1 .CustomRuleKind , Rationale : "e2e test" },
10611053 },
1062- expectRules : []string {crName },
10631054 },
10641055 "from-scratch" : {
1065- spec : complianceoperatorv1.TailoredProfileSpec {
1066- Title : "E2E From-Scratch" ,
1067- Description : "From-scratch TP with regular rules" ,
1068- EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1069- {Name : "ocp4-api-server-audit-log-maxbackup" , Kind : complianceoperatorv1 .RuleKind , Rationale : "e2e test" },
1070- },
1056+ Title : "E2E From-Scratch" ,
1057+ Description : "From-scratch TP with regular rules" ,
1058+ EnableRules : []complianceoperatorv1.RuleReferenceSpec {
1059+ {Name : "ocp4-api-server-audit-log-maxbackup" , Kind : complianceoperatorv1 .RuleKind , Rationale : "e2e test" },
10711060 },
1072- expectRules : []string {"ocp4-api-server-audit-log-maxbackup" },
10731061 },
10741062 }
10751063
1076- for name , variant := range variants {
1064+ for name , spec := range variants {
10771065 t .Run (name , func (t * testing.T ) {
10781066 tpName := testID + "-" + name
10791067
@@ -1082,7 +1070,7 @@ func TestComplianceV2TailoredProfileVariants(t *testing.T) {
10821070 Name : tpName ,
10831071 Namespace : coNamespaceV2 ,
10841072 },
1085- Spec : variant . spec ,
1073+ Spec : spec ,
10861074 }
10871075 require .NoErrorf (t , dynClient .Create (ctx , tp ), "failed to create TP %s" , tpName )
10881076 t .Cleanup (func () {
@@ -1106,16 +1094,16 @@ func TestComplianceV2TailoredProfileVariants(t *testing.T) {
11061094 require .NoError (t , err )
11071095 assert .Greater (t , len (detail .GetRules ()), 0 , "TP should have at least one rule" )
11081096
1109- ruleNames := make (map [ string ] bool , len (detail .GetRules ()))
1097+ ruleNames := make ([] string , 0 , len (detail .GetRules ()))
11101098 for _ , r := range detail .GetRules () {
1111- ruleNames [ r .GetName ()] = true
1099+ ruleNames = append ( ruleNames , r .GetName ())
11121100 }
11131101
1114- for _ , expected := range variant . expectRules {
1115- assert .Truef (t , ruleNames [ expected ], "expected rule %q not found in TP" , expected )
1102+ for _ , r := range spec . EnableRules {
1103+ assert .Contains (t , ruleNames , r . Name , "expected rule not found" )
11161104 }
1117- for _ , rejected := range variant . rejectRules {
1118- assert .Falsef (t , ruleNames [ rejected ], "rejected rule %q should not be in TP" , rejected )
1105+ for _ , r := range spec . DisableRules {
1106+ assert .NotContains (t , ruleNames , r . Name , "found unexpected rule" )
11191107 }
11201108 })
11211109 }
0 commit comments