diff --git a/api/v1/serviceinstance_validating_webhook_test.go b/api/v1/serviceinstance_validating_webhook_test.go index 3323830d..f2270031 100644 --- a/api/v1/serviceinstance_validating_webhook_test.go +++ b/api/v1/serviceinstance_validating_webhook_test.go @@ -4,6 +4,7 @@ import ( "github.com/SAP/sap-btp-service-operator/api" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "time" ) var _ = Describe("Service Instance Webhook Test", func() { @@ -24,6 +25,25 @@ var _ = Describe("Service Instance Webhook Test", func() { Expect(err.Error()).To(ContainSubstring("changing the btpAccessCredentialsSecret for an existing instance is not allowed")) }) }) + When("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with not a date", func() { + It("should not return error from webhook", func() { + instance.Annotations = map[string]string{ + api.IgnoreNonTransientErrorTimestampAnnotation: "true", + } + _, err := instance.ValidateUpdate(instance) + Expect(err).To(HaveOccurred()) + + }) + }) + When("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with future date", func() { + It("should not return error from webhook", func() { + instance.Annotations = map[string]string{ + api.IgnoreNonTransientErrorTimestampAnnotation: time.Now().Add(48 * time.Hour).Format(time.RFC3339), + } + _, err := instance.ValidateUpdate(instance) + Expect(err).To(HaveOccurred()) + }) + }) }) Context("Validate Delete", func() { @@ -53,5 +73,26 @@ var _ = Describe("Service Instance Webhook Test", func() { Expect(err).ToNot(HaveOccurred()) }) }) + Context("Validate Create", func() { + When("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with not a date", func() { + It("should not return error from webhook", func() { + instance.Annotations = map[string]string{ + api.IgnoreNonTransientErrorTimestampAnnotation: "true", + } + _, err := instance.ValidateCreate() + Expect(err).To(HaveOccurred()) + + }) + }) + When("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with future date", func() { + It("should not return error from webhook", func() { + instance.Annotations = map[string]string{ + api.IgnoreNonTransientErrorTimestampAnnotation: time.Now().Add(48 * time.Hour).Format(time.RFC3339), + } + _, err := instance.ValidateCreate() + Expect(err).To(HaveOccurred()) + }) + }) + }) }) })