github.com/kyma-project/kyma/components/asset-store-controller-manager@v0.0.0-20191203152857-3792b5df17c5/internal/finalizer/finalizer_test.go (about) 1 package finalizer_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-project/kyma/components/asset-store-controller-manager/internal/finalizer" 7 "github.com/onsi/gomega" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 ) 10 11 const testFinalizerName = "test.finalizer" 12 13 func TestFinalizerAdder_AddTo(t *testing.T) { 14 //Given 15 g := gomega.NewGomegaWithT(t) 16 17 instance := &metav1.ObjectMeta{ 18 Finalizers: []string{"test", "test2"}, 19 } 20 bucketFinalizer := finalizer.New(testFinalizerName) 21 22 //When 23 bucketFinalizer.AddTo(instance) 24 bucketFinalizer.AddTo(instance) 25 26 //Then 27 g.Expect(instance.Finalizers).To(gomega.HaveLen(3)) 28 g.Expect(instance.Finalizers).To(gomega.ContainElement(testFinalizerName)) 29 } 30 31 func TestFinalizerAdder_DeleteFrom(t *testing.T) { 32 //Given 33 g := gomega.NewGomegaWithT(t) 34 35 instance := &metav1.ObjectMeta{ 36 Finalizers: []string{"test", testFinalizerName, "test2"}, 37 } 38 bucketFinalizer := finalizer.New(testFinalizerName) 39 40 //When 41 bucketFinalizer.DeleteFrom(instance) 42 43 //Then 44 g.Expect(instance.Finalizers).NotTo(gomega.ContainElement(testFinalizerName)) 45 } 46 47 func TestFinalizerAdder_IsDefinedIn(t *testing.T) { 48 t.Run("Defined", func(t *testing.T) { 49 //Given 50 g := gomega.NewGomegaWithT(t) 51 52 instance := &metav1.ObjectMeta{ 53 Finalizers: []string{"foo", testFinalizerName, "bar"}, 54 } 55 bucketFinalizer := finalizer.New(testFinalizerName) 56 57 //When 58 result := bucketFinalizer.IsDefinedIn(instance) 59 60 //Then 61 g.Expect(result).To(gomega.BeTrue()) 62 }) 63 64 t.Run("NotDefined", func(t *testing.T) { 65 //Given 66 g := gomega.NewGomegaWithT(t) 67 68 instance := &metav1.ObjectMeta{ 69 Finalizers: []string{"foo", "bar"}, 70 } 71 72 bucketFinalizer := finalizer.New(testFinalizerName) 73 74 //When 75 result := bucketFinalizer.IsDefinedIn(instance) 76 77 //Then 78 g.Expect(result).NotTo(gomega.BeTrue()) 79 }) 80 }