@@ -577,8 +577,8 @@ var _ = Describe("Test templatization", Ordered, func() {
577
577
e2eBaseName = "case13-e2e-objectname-var"
578
578
invalidPolicyYAML = case13RsrcPath + "/case13_objectname_var_invalid_name.yaml"
579
579
invalidPolicyName = "case13-invalid-name"
580
- emptyPolicyYAML = case13RsrcPath + "/case13_objectname_var_empty_name .yaml"
581
- emptyPolicyName = "case13-empty -name"
580
+ outsidePolicyYAML = case13RsrcPath + "/case13_objectname_var_outside_name .yaml"
581
+ outsidePolicyName = "case13-outside -name"
582
582
allSkippedPolicyYAML = case13RsrcPath + "/case13_objectname_var_all_skipped.yaml"
583
583
allSkippedPolicyName = "case13-objectname-var-all-skipped"
584
584
)
@@ -636,26 +636,42 @@ var _ = Describe("Test templatization", Ordered, func() {
636
636
}
637
637
})
638
638
639
- It ("Should fail when the name is empty after template resolution " , func (ctx SpecContext ) {
640
- By ("Applying the " + emptyPolicyName + " ConfigurationPolicy" )
641
- utils .Kubectl ("apply" , "-n" , testNamespace , "-f" , emptyPolicyYAML )
639
+ It ("Should succeed when context vars are in use but name/namespace are left empty " , func (ctx SpecContext ) {
640
+ By ("Applying the " + outsidePolicyName + " ConfigurationPolicy" )
641
+ utils .Kubectl ("apply" , "-n" , testNamespace , "-f" , outsidePolicyYAML )
642
642
643
- By ("By verifying that the ConfigurationPolicy is noncompliant " )
643
+ By ("By verifying that the ConfigurationPolicy is compliant and has the correct related objects " )
644
644
Eventually (func (g Gomega ) {
645
645
managedPlc := utils .GetWithTimeout (
646
646
clientManagedDynamic ,
647
647
gvrConfigPolicy ,
648
- emptyPolicyName ,
648
+ outsidePolicyName ,
649
649
testNamespace ,
650
650
true ,
651
651
defaultTimeoutSeconds ,
652
652
)
653
653
654
- utils .CheckComplianceStatus (g , managedPlc , "NonCompliant" )
655
- g .Expect (utils .GetStatusMessage (managedPlc )).To (Equal (
656
- "The object definition's name must match the selected name after template resolution" ,
657
- ))
654
+ utils .CheckComplianceStatus (g , managedPlc , "Compliant" )
655
+ g .Expect (utils .GetStatusMessage (managedPlc )).Should (Equal (fmt .Sprintf (
656
+ "configmaps [case13-e2e-objectname-var3] found as specified in namespace %s" , e2eBaseName )))
657
+
658
+ relatedObjects , _ , _ := unstructured .NestedSlice (managedPlc .Object , "status" , "relatedObjects" )
659
+ g .Expect (relatedObjects ).To (HaveLen (1 ))
660
+ relatedObject , ok := relatedObjects [0 ].(map [string ]interface {})
661
+ g .Expect (ok ).To (BeTrue (), "Related object is not a map" )
662
+ relatedObject1NS , _ , _ := unstructured .NestedString (relatedObject , "object" , "metadata" , "name" )
663
+ g .Expect (relatedObject1NS ).To (
664
+ Equal (fmt .Sprintf ("%s%d" , e2eBaseName , 3 )),
665
+ "Related object name should match" )
658
666
}, defaultTimeoutSeconds , 1 ).Should (Succeed ())
667
+
668
+ By ("By verifying the ConfigMaps" )
669
+ cm , err := clientManaged .CoreV1 ().ConfigMaps (e2eBaseName ).Get (
670
+ ctx , "case13-e2e-objectname-var3" , metav1.GetOptions {})
671
+ Expect (err ).ToNot (HaveOccurred ())
672
+ Expect (cm .ObjectMeta .Labels ).To (HaveKeyWithValue ("case13" , "passed" ))
673
+ Expect (cm .ObjectMeta .Labels ).To (HaveKeyWithValue ("object-name" , cm .GetName ()))
674
+ Expect (cm .ObjectMeta .Labels ).To (HaveKeyWithValue ("object-namespace" , cm .GetNamespace ()))
659
675
})
660
676
661
677
It ("Should fail when the name doesn't match after template resolution" , func (ctx SpecContext ) {
@@ -705,7 +721,7 @@ var _ = Describe("Test templatization", Ordered, func() {
705
721
AfterEach (func () {
706
722
utils .KubectlDelete ("configurationpolicy" , policyName , "-n" , testNamespace )
707
723
utils .KubectlDelete ("configurationpolicy" , invalidPolicyName , "-n" , testNamespace )
708
- utils .KubectlDelete ("configurationpolicy" , emptyPolicyName , "-n" , testNamespace )
724
+ utils .KubectlDelete ("configurationpolicy" , outsidePolicyName , "-n" , testNamespace )
709
725
utils .KubectlDelete ("configurationpolicy" , allSkippedPolicyName , "-n" , testNamespace )
710
726
utils .KubectlDelete ("configmaps" , "-n" , e2eBaseName , "--all" )
711
727
})
0 commit comments