@@ -382,6 +382,70 @@ func TestApplyValidatingConfiguration(t *testing.T) {
382382 }
383383}
384384
385+ func TestDeleteValidatingConfiguration (t * testing.T ) {
386+ defaultHook := & admissionregistrationv1.ValidatingWebhookConfiguration {}
387+ defaultHook .SetName ("test" )
388+ deleteEvent := "ValidatingWebhookConfigurationDeleted"
389+
390+ tests := []struct {
391+ name string
392+ expectModified bool
393+ existing func () * admissionregistrationv1.ValidatingWebhookConfiguration
394+ input func () * admissionregistrationv1.ValidatingWebhookConfiguration
395+ expectedEvents []string
396+ }{
397+ {
398+ name : "Should delete webhook if it exists" ,
399+ expectModified : true ,
400+ input : func () * admissionregistrationv1.ValidatingWebhookConfiguration {
401+ hook := defaultHook .DeepCopy ()
402+ return hook
403+ },
404+ existing : func () * admissionregistrationv1.ValidatingWebhookConfiguration {
405+ hook := defaultHook .DeepCopy ()
406+ return hook
407+ },
408+ expectedEvents : []string {deleteEvent },
409+ },
410+ {
411+ name : "Should do nothing if webhook does not exist" ,
412+ expectModified : false ,
413+ input : func () * admissionregistrationv1.ValidatingWebhookConfiguration {
414+ hook := defaultHook .DeepCopy ()
415+ return hook
416+ },
417+ expectedEvents : []string {},
418+ },
419+ }
420+
421+ for _ , test := range tests {
422+ t .Run (test .name , func (t * testing.T ) {
423+ existingHooks := []runtime.Object {}
424+ if test .existing != nil {
425+ existingHooks = append (existingHooks , test .existing ())
426+ }
427+ client := fake .NewSimpleClientset (existingHooks ... )
428+ recorder := events .NewInMemoryRecorder ("test" )
429+
430+ testApply := func (expectModify bool ) {
431+ updatedHook , modified , err := DeleteValidatingWebhookConfiguration (
432+ context .TODO (),
433+ client .AdmissionregistrationV1 (),
434+ recorder , test .input ())
435+ if err != nil {
436+ t .Fatal (err )
437+ }
438+ if expectModify != modified {
439+ t .Errorf ("expected modified to be equal %v, got %v: %#v" , expectModify , modified , updatedHook )
440+ }
441+ }
442+
443+ testApply (test .expectModified )
444+ assertEvents (t , test .name , test .expectedEvents , recorder .Events ())
445+ })
446+ }
447+ }
448+
385449func TestApplyValidatingAdmissionPolicyConfiguration (t * testing.T ) {
386450 defaultPolicy := & admissionregistrationv1beta1.ValidatingAdmissionPolicy {}
387451 defaultPolicy .SetName ("test" )
0 commit comments