@@ -276,6 +276,89 @@ var _ = Describe("Cfg", func() {
276276 checkResource (c .Resources [0 ], resWithoutPlural )
277277 })
278278
279+ It ("RemoveResource should remove the resource if it exists" , func () {
280+ c .Resources = append (c .Resources , res )
281+ l := len (c .Resources )
282+ Expect (c .RemoveResource (res .GVK )).To (Succeed ())
283+ Expect (c .Resources ).To (HaveLen (l - 1 ))
284+ Expect (c .HasResource (res .GVK )).To (BeFalse ())
285+ })
286+
287+ It ("RemoveResource should return an error if the resource does not exist" , func () {
288+ Expect (c .RemoveResource (res .GVK )).NotTo (Succeed ())
289+ })
290+
291+ It ("RemoveResource should remove only the specified resource" , func () {
292+ res2 := resource.Resource {
293+ GVK : resource.GVK {
294+ Group : "group" ,
295+ Version : "v1" ,
296+ Kind : "OtherKind" ,
297+ },
298+ }
299+ c .Resources = append (c .Resources , res , res2 )
300+ Expect (c .Resources ).To (HaveLen (2 ))
301+
302+ Expect (c .RemoveResource (res .GVK )).To (Succeed ())
303+ Expect (c .Resources ).To (HaveLen (1 ))
304+ Expect (c .HasResource (res .GVK )).To (BeFalse ())
305+ Expect (c .HasResource (res2 .GVK )).To (BeTrue ())
306+ })
307+
308+ It ("SetResourceWebhooks should update webhook configuration" , func () {
309+ resWithWebhooks := resource.Resource {
310+ GVK : resource.GVK {
311+ Group : "group" ,
312+ Version : "v1" ,
313+ Kind : "Kind" ,
314+ },
315+ Webhooks : & resource.Webhooks {
316+ WebhookVersion : "v1" ,
317+ Defaulting : true ,
318+ Validation : true ,
319+ },
320+ }
321+ c .Resources = append (c .Resources , resWithWebhooks )
322+
323+ // Update to remove defaulting webhook
324+ newWebhooks := & resource.Webhooks {
325+ WebhookVersion : "v1" ,
326+ Defaulting : false ,
327+ Validation : true ,
328+ }
329+ Expect (c .SetResourceWebhooks (resWithWebhooks .GVK , newWebhooks )).To (Succeed ())
330+
331+ updated , err := c .GetResource (resWithWebhooks .GVK )
332+ Expect (err ).NotTo (HaveOccurred ())
333+ Expect (updated .Webhooks .Defaulting ).To (BeFalse ())
334+ Expect (updated .Webhooks .Validation ).To (BeTrue ())
335+ })
336+
337+ It ("SetResourceWebhooks should clear webhooks when nil provided" , func () {
338+ resWithWebhooks := resource.Resource {
339+ GVK : resource.GVK {
340+ Group : "group" ,
341+ Version : "v1" ,
342+ Kind : "Kind" ,
343+ },
344+ Webhooks : & resource.Webhooks {
345+ WebhookVersion : "v1" ,
346+ Defaulting : true ,
347+ },
348+ }
349+ c .Resources = append (c .Resources , resWithWebhooks )
350+
351+ Expect (c .SetResourceWebhooks (resWithWebhooks .GVK , nil )).To (Succeed ())
352+
353+ updated , err := c .GetResource (resWithWebhooks .GVK )
354+ Expect (err ).NotTo (HaveOccurred ())
355+ Expect (updated .Webhooks ).To (BeNil ())
356+ })
357+
358+ It ("SetResourceWebhooks should fail if resource not found" , func () {
359+ Expect (c .SetResourceWebhooks (res .GVK , nil )).NotTo (Succeed ())
360+ })
361+
279362 It ("HasGroup should return false with no tracked resources" , func () {
280363 Expect (c .HasGroup (res .Group )).To (BeFalse ())
281364 })
0 commit comments