@@ -25,37 +25,20 @@ var _ = Describe("Test error handling", func() {
2525 Expect (err ).To (BeNil ())
2626 })
2727 It ("should not override remediationAction if doesn't exist on parent policy" , func () {
28- By (
29- "Creating ../resources/case10_template_sync_error_test/remediation-action-not-exists.yaml on the hub " +
30- "in ns:" + clusterNamespaceOnHub ,
31- )
32- _ , err := kubectlHub (
33- "apply" ,
34- "-f" ,
35- "../resources/case10_template_sync_error_test/remediation-action-not-exists.yaml" ,
36- "-n" ,
37- clusterNamespaceOnHub ,
38- )
39- Expect (err ).Should (BeNil ())
28+ hubApplyPolicy ("case10-remediation-action-not-exists" ,
29+ "../resources/case10_template_sync_error_test/remediation-action-not-exists.yaml" )
30+
4031 Eventually (func () interface {} {
4132 trustedPlc := utils .GetWithTimeout (clientManagedDynamic , gvrConfigurationPolicy ,
4233 "case10-remediation-action-not-exists-configpolicy" , clusterNamespace , true ,
4334 defaultTimeoutSeconds )
4435
4536 return trustedPlc .Object ["spec" ].(map [string ]interface {})["remediationAction" ]
4637 }, defaultTimeoutSeconds , 1 ).Should (Equal ("inform" ))
47- By (
48- "Patching ../resources/case10_template_sync_error_test/remediation-action-not-exists2.yaml on the hub " +
49- "in ns:" + clusterNamespace ,
50- )
51- _ , err = kubectlHub (
52- "apply" ,
53- "-f" ,
54- "../resources/case10_template_sync_error_test/remediation-action-not-exists2.yaml" ,
55- "-n" ,
56- clusterNamespaceOnHub ,
57- )
58- Expect (err ).Should (BeNil ())
38+
39+ hubApplyPolicy ("case10-remediation-action-not-exists" ,
40+ "../resources/case10_template_sync_error_test/remediation-action-not-exists2.yaml" )
41+
5942 By ("Checking the case10-remediation-action-not-exists-configpolicy CR" )
6043 yamlTrustedPlc := utils .ParseYaml (
6144 "../resources/case10_template_sync_error_test/remediation-action-not-exists-configpolicy.yaml" )
@@ -68,18 +51,9 @@ var _ = Describe("Test error handling", func() {
6851 }, defaultTimeoutSeconds , 1 ).Should (utils .SemanticEqual (yamlTrustedPlc .Object ["spec" ]))
6952 })
7053 It ("should generate decode err event" , func () {
71- By (
72- "Creating ../resources/case10_template_sync_error_test/template-decode-error.yaml on hub cluster " +
73- "in ns:" + clusterNamespaceOnHub ,
74- )
75- _ , err := kubectlHub (
76- "apply" ,
77- "-f" ,
78- "../resources/case10_template_sync_error_test/template-decode-error.yaml" ,
79- "-n" ,
80- clusterNamespaceOnHub ,
81- )
82- Expect (err ).Should (BeNil ())
54+ hubApplyPolicy ("case10-template-decode-error" ,
55+ "../resources/case10_template_sync_error_test/template-decode-error.yaml" )
56+
8357 By ("Checking for event with decode err on managed cluster in ns:" + clusterNamespace )
8458 Eventually (
8559 checkForEvent ("case10-template-decode-error" , "template-error; Failed to decode policy template" ),
@@ -88,16 +62,9 @@ var _ = Describe("Test error handling", func() {
8862 ).Should (BeTrue ())
8963 })
9064 It ("should generate missing name err event" , func () {
91- By ("Creating ../resources/case10_template_sync_error_test/template-name-error.yaml on hub cluster in ns:" +
92- clusterNamespaceOnHub )
93- _ , err := kubectlHub (
94- "apply" ,
95- "-f" ,
96- "../resources/case10_template_sync_error_test/template-name-error.yaml" ,
97- "-n" ,
98- clusterNamespaceOnHub ,
99- )
100- Expect (err ).Should (BeNil ())
65+ hubApplyPolicy ("case10-template-name-error" ,
66+ "../resources/case10_template_sync_error_test/template-name-error.yaml" )
67+
10168 By ("Checking for event with missing name err on managed cluster in ns:" + clusterNamespace )
10269 Eventually (
10370 checkForEvent ("case10-template-name-error" , "template-error; Failed to get name from policy" ),
@@ -106,18 +73,9 @@ var _ = Describe("Test error handling", func() {
10673 ).Should (BeTrue ())
10774 })
10875 It ("should generate mapping err event" , func () {
109- By (
110- "Creating ../resources/case10_template_sync_error_test/template-mapping-error.yaml on hub cluster " +
111- "in ns:" + clusterNamespaceOnHub ,
112- )
113- _ , err := kubectlHub (
114- "apply" ,
115- "-f" ,
116- "../resources/case10_template_sync_error_test/template-mapping-error.yaml" ,
117- "-n" ,
118- clusterNamespaceOnHub ,
119- )
120- Expect (err ).Should (BeNil ())
76+ hubApplyPolicy ("case10-template-mapping-error" ,
77+ "../resources/case10_template_sync_error_test/template-mapping-error.yaml" )
78+
12179 By ("Checking for event with decode err on managed cluster in ns:" + clusterNamespace )
12280 Eventually (
12381 checkForEvent ("case10-template-mapping-error" , "template-error; Mapping not found" ),
@@ -126,49 +84,26 @@ var _ = Describe("Test error handling", func() {
12684 ).Should (BeTrue ())
12785 })
12886 It ("should generate duplicate policy template err event" , func () {
129- By (
130- "Creating ../resources/case10_template_sync_error_test/working-policy-duplicate.yaml on hub cluster " +
131- "in ns:" + clusterNamespaceOnHub ,
132- )
133- _ , err := kubectlHub (
134- "apply" ,
135- "-f" ,
136- "../resources/case10_template_sync_error_test/working-policy.yaml" ,
137- "-n" ,
138- clusterNamespaceOnHub ,
139- )
140- Expect (err ).Should (BeNil ())
87+ hubApplyPolicy ("case10-test-policy" ,
88+ "../resources/case10_template_sync_error_test/working-policy.yaml" )
89+
14190 // wait for original policy to be processed before creating duplicate policy
14291 utils .GetWithTimeout (clientManagedDynamic , gvrConfigurationPolicy ,
14392 "case10-config-policy" , clusterNamespace , true , defaultTimeoutSeconds )
144- _ , err = kubectlHub (
145- "apply" ,
146- "-f" ,
147- "../resources/case10_template_sync_error_test/working-policy-duplicate.yaml" ,
148- "-n" ,
149- clusterNamespaceOnHub ,
150- )
151- Expect (err ).Should (BeNil ())
152- By ("Creating event with duplicate err on managed cluster in ns:" + clusterNamespace )
93+
94+ hubApplyPolicy ("case10-test-policy-duplicate" ,
95+ "../resources/case10_template_sync_error_test/working-policy-duplicate.yaml" )
96+
97+ By ("Checking for event with duplicate err on managed cluster in ns:" + clusterNamespace )
15398 Eventually (
15499 checkForEvent ("case10-test-policy-duplicate" , "Template name must be unique" ),
155100 defaultTimeoutSeconds ,
156101 1 ,
157102 ).Should (BeTrue ())
158103 })
159104 It ("should create other objects, even when one is invalid" , func () {
160- By (
161- "Creating ../resources/case10_template_sync_error_test/middle-template-error.yaml on hub cluster " +
162- "in ns:" + clusterNamespaceOnHub ,
163- )
164- _ , err := kubectlHub (
165- "apply" ,
166- "-f" ,
167- "../resources/case10_template_sync_error_test/middle-template-error.yaml" ,
168- "-n" ,
169- clusterNamespaceOnHub ,
170- )
171- Expect (err ).Should (BeNil ())
105+ hubApplyPolicy ("case10-middle-tmpl" ,
106+ "../resources/case10_template_sync_error_test/middle-template-error.yaml" )
172107
173108 By ("Checking for the other template objects" )
174109 utils .GetWithTimeout (clientManagedDynamic , gvrConfigurationPolicy ,
@@ -184,24 +119,17 @@ var _ = Describe("Test error handling", func() {
184119 ).Should (BeTrue ())
185120 })
186121 It ("should remove the complianceState on a template only after an error is resolved" , func () {
187- By ("Creating ../resources/case10_template_sync_error_test/working-policy.yaml on hub cluster in ns:" +
188- clusterNamespaceOnHub )
189- _ , err := kubectlHub (
190- "apply" ,
191- "-f" ,
192- "../resources/case10_template_sync_error_test/working-policy.yaml" ,
193- "-n" ,
194- clusterNamespaceOnHub ,
195- )
196- Expect (err ).Should (BeNil ())
122+ hubApplyPolicy ("case10-test-policy" ,
123+ "../resources/case10_template_sync_error_test/working-policy.yaml" )
124+
197125 utils .ListWithTimeout (clientManagedDynamic , gvrConfigurationPolicy , metav1.ListOptions {},
198126 1 , true , defaultTimeoutSeconds )
199127
200128 By ("Manually updating the status on the created configuration policy" )
201129 compliancePatch := []byte (`[{"op":"add","path":"/status","value":{"compliant":"testing"}}]` )
202130 // can't just use kubectl - status is a sub-resource
203131 cfgInt := clientManagedDynamic .Resource (gvrConfigurationPolicy ).Namespace (clusterNamespace )
204- _ , err = cfgInt .Patch (context .TODO (), "case10-config-policy" , types .JSONPatchType ,
132+ _ , err : = cfgInt .Patch (context .TODO (), "case10-config-policy" , types .JSONPatchType ,
205133 compliancePatch , metav1.PatchOptions {}, "status" )
206134 Expect (err ).Should (BeNil ())
207135
@@ -241,14 +169,8 @@ var _ = Describe("Test error handling", func() {
241169 Expect (compState ).To (Equal ("testing" ))
242170
243171 By ("Re-applying the working policy" )
244- _ , err = kubectlHub (
245- "apply" ,
246- "-f" ,
247- "../resources/case10_template_sync_error_test/working-policy.yaml" ,
248- "-n" ,
249- clusterNamespaceOnHub ,
250- )
251- Expect (err ).Should (BeNil ())
172+ hubApplyPolicy ("case10-test-policy" ,
173+ "../resources/case10_template_sync_error_test/working-policy.yaml" )
252174
253175 By ("Checking that the complianceState is removed on the configuration policy" )
254176 Eventually (func () bool {
@@ -263,18 +185,8 @@ var _ = Describe("Test error handling", func() {
263185 }, defaultTimeoutSeconds , 1 ).Should (BeFalse ())
264186 })
265187 It ("should throw a noncompliance event if a non-configurationpolicy uses a hub template" , func () {
266- By (
267- "Creating ../resources/case10_template_sync_error_test/non-config-hubtemplate.yaml on hub cluster " +
268- "in ns:" + clusterNamespaceOnHub ,
269- )
270- _ , err := kubectlHub (
271- "apply" ,
272- "-f" ,
273- "../resources/case10_template_sync_error_test/non-config-hubtemplate.yaml" ,
274- "-n" ,
275- clusterNamespaceOnHub ,
276- )
277- Expect (err ).Should (BeNil ())
188+ hubApplyPolicy ("case10-bad-hubtemplate" ,
189+ "../resources/case10_template_sync_error_test/non-config-hubtemplate.yaml" )
278190
279191 By ("Checking for the error event" )
280192 Eventually (
@@ -284,18 +196,8 @@ var _ = Describe("Test error handling", func() {
284196 ).Should (BeTrue ())
285197 })
286198 It ("should throw a noncompliance event if the template object is invalid" , func () {
287- By (
288- "Creating ../resources/case10_template_sync_error_test/invalid-severity-template.yaml on hub cluster " +
289- "in ns:" + clusterNamespaceOnHub ,
290- )
291- _ , err := kubectlHub (
292- "apply" ,
293- "-f" ,
294- "../resources/case10_template_sync_error_test/invalid-severity-template.yaml" ,
295- "-n" ,
296- clusterNamespaceOnHub ,
297- )
298- Expect (err ).Should (BeNil ())
199+ hubApplyPolicy ("case10-invalid-severity" ,
200+ "../resources/case10_template_sync_error_test/invalid-severity-template.yaml" )
299201
300202 By ("Checking for the error event" )
301203 Eventually (
@@ -305,16 +207,8 @@ var _ = Describe("Test error handling", func() {
305207 ).Should (BeTrue ())
306208 })
307209 It ("should not throw a noncompliance event if the policy-templates array is empty" , func () {
308- By ("Creating ../resources/case10_template_sync_error_test/empty-templates.yaml on hub cluster in ns:" +
309- clusterNamespaceOnHub )
310- _ , err := kubectlHub (
311- "apply" ,
312- "-f" ,
313- "../resources/case10_template_sync_error_test/empty-templates.yaml" ,
314- "-n" ,
315- clusterNamespaceOnHub ,
316- )
317- Expect (err ).Should (BeNil ())
210+ hubApplyPolicy ("case10-empty-templates" ,
211+ "../resources/case10_template_sync_error_test/empty-templates.yaml" )
318212
319213 By ("Checking for the error event" )
320214 Eventually (
@@ -325,6 +219,7 @@ var _ = Describe("Test error handling", func() {
325219 })
326220})
327221
222+ // Checks for an event on the managed cluster
328223func checkForEvent (policyName , msgSubStr string ) func () bool {
329224 return func () bool {
330225 eventInterface := clientManagedDynamic .Resource (gvrEvent ).Namespace (clusterNamespace )
0 commit comments