@@ -700,6 +700,62 @@ var _ = Describe("Controllerutil", func() {
700
700
})
701
701
})
702
702
703
+ Describe ("AddFinalizer, which returns an indication of whether it modified the input object's finalizers list," , func () {
704
+ deploy = & appsv1.Deployment {
705
+ ObjectMeta : metav1.ObjectMeta {
706
+ Finalizers : []string {},
707
+ },
708
+ }
709
+
710
+ When ("the input object's finalizers list has no instances of the input finalizer" , func () {
711
+ It ("should return true" , func () {
712
+ Expect (controllerutil .AddFinalizer (deploy , testFinalizer )).To (BeTrue ())
713
+ })
714
+ It ("should add the input finalizer to the input object's finalizers list" , func () {
715
+ Expect (deploy .ObjectMeta .GetFinalizers ()).To (Equal ([]string {testFinalizer }))
716
+ })
717
+ })
718
+
719
+ When ("the input object's finalizers list has an instance of the input finalizer" , func () {
720
+ It ("should return false" , func () {
721
+ Expect (controllerutil .AddFinalizer (deploy , testFinalizer )).To (BeFalse ())
722
+ })
723
+ It ("should not modify the input object's finalizers list" , func () {
724
+ Expect (deploy .ObjectMeta .GetFinalizers ()).To (Equal ([]string {testFinalizer }))
725
+ })
726
+ })
727
+ })
728
+
729
+ Describe ("RemoveFinalizer, which returns an indication of whether it modified the input object's finalizers list," , func () {
730
+ When ("the input object's finalizers list has no instances of the input finalizer" , func () {
731
+ It ("should return false" , func () {
732
+ Expect (controllerutil .RemoveFinalizer (deploy , testFinalizer1 )).To (BeFalse ())
733
+ })
734
+ It ("should not modify the input object's finalizers list" , func () {
735
+ Expect (deploy .ObjectMeta .GetFinalizers ()).To (Equal ([]string {testFinalizer }))
736
+ })
737
+ })
738
+
739
+ When ("the input object's finalizers list has one instance of the input finalizer" , func () {
740
+ It ("should return true" , func () {
741
+ Expect (controllerutil .RemoveFinalizer (deploy , testFinalizer )).To (BeTrue ())
742
+ })
743
+ It ("should remove the instance of the input finalizer from the input object's finalizers list" , func () {
744
+ Expect (deploy .ObjectMeta .GetFinalizers ()).To (Equal ([]string {}))
745
+ })
746
+ })
747
+
748
+ When ("the input object's finalizers list has multiple instances of the input finalizer" , func () {
749
+ It ("should return true" , func () {
750
+ deploy .SetFinalizers (append (deploy .Finalizers , testFinalizer , testFinalizer ))
751
+ Expect (controllerutil .RemoveFinalizer (deploy , testFinalizer )).To (BeTrue ())
752
+ })
753
+ It ("should remove each instance of the input finalizer from the input object's finalizers list" , func () {
754
+ Expect (deploy .ObjectMeta .GetFinalizers ()).To (Equal ([]string {}))
755
+ })
756
+ })
757
+ })
758
+
703
759
Describe ("ContainsFinalizer" , func () {
704
760
It ("should check that finalizer is present" , func () {
705
761
controllerutil .AddFinalizer (deploy , testFinalizer )
@@ -715,6 +771,7 @@ var _ = Describe("Controllerutil", func() {
715
771
})
716
772
717
773
const testFinalizer = "foo.bar.baz"
774
+ const testFinalizer1 = testFinalizer + "1"
718
775
719
776
var _ runtime.Object = & errRuntimeObj {}
720
777
var _ metav1.Object = & errMetaObj {}
0 commit comments