@@ -11,7 +11,9 @@ import (
1111 . "github.com/onsi/gomega"
1212 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14+ "k8s.io/apimachinery/pkg/runtime"
1415 "k8s.io/apimachinery/pkg/types"
16+ policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
1517 "open-cluster-management.io/governance-policy-propagator/test/utils"
1618)
1719
@@ -110,6 +112,35 @@ var _ = Describe("Test error handling", func() {
110112 1 ,
111113 ).Should (BeTrue ())
112114 })
115+ It ("should generate creation err event" , func () {
116+ policyName := "case10-invalid-name-error"
117+ statusMsg := "template-error; Failed to create policy template:"
118+
119+ hubApplyPolicy (policyName ,
120+ yamlBasePath + "invalid-name-error.yaml" )
121+
122+ By ("Checking for event with creation err on managed cluster in ns:" + clusterNamespace )
123+ Eventually (
124+ checkForEvent (policyName , statusMsg ),
125+ defaultTimeoutSeconds ,
126+ 1 ,
127+ ).Should (BeTrue ())
128+ By ("Checking if policy status is noncompliant" )
129+ hubPlc := utils .GetWithTimeout (
130+ clientHubDynamic ,
131+ gvrPolicy ,
132+ policyName ,
133+ clusterNamespaceOnHub ,
134+ true ,
135+ defaultTimeoutSeconds )
136+ var plc * policiesv1.Policy
137+ err := runtime .DefaultUnstructuredConverter .FromUnstructured (hubPlc .Object , & plc )
138+ Expect (err ).ToNot (HaveOccurred ())
139+ Expect (plc .Status .Details ).To (HaveLen (1 ))
140+ Expect (plc .Status .Details [0 ].History ).To (HaveLen (1 ))
141+ Expect (plc .Status .Details [0 ].TemplateMeta .GetName ()).To (Equal ("case10_invalid-name" ))
142+ Expect (plc .Status .Details [0 ].History [0 ].Message ).To (ContainSubstring (statusMsg ))
143+ })
113144 It ("should generate unsupported object err event" , func () {
114145 hubApplyPolicy ("case10-unsupported-object" ,
115146 yamlBasePath + "unsupported-object-error.yaml" )
0 commit comments