11package v1
22
33import (
4- "fmt"
54 "github.com/SAP/sap-btp-service-operator/api/common"
65 . "github.com/onsi/ginkgo"
76 . "github.com/onsi/gomega"
8- "time"
97)
108
119var _ = Describe ("Service Instance Webhook Test" , func () {
@@ -26,27 +24,6 @@ var _ = Describe("Service Instance Webhook Test", func() {
2624 Expect (err .Error ()).To (ContainSubstring ("changing the btpAccessCredentialsSecret for an existing instance is not allowed" ))
2725 })
2826 })
29- When ("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with not a date" , func () {
30- It ("should return error from webhook" , func () {
31- instance .Annotations = map [string ]string {
32- common .IgnoreNonTransientErrorAnnotation : "true" ,
33- common .IgnoreNonTransientErrorTimestampAnnotation : "true" ,
34- }
35- _ , err := instance .ValidateUpdate (instance )
36- Expect (err ).To (HaveOccurred ())
37-
38- })
39- })
40- When ("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with future date" , func () {
41- It ("should return error from webhook" , func () {
42- instance .Annotations = map [string ]string {
43- common .IgnoreNonTransientErrorAnnotation : "true" ,
44- common .IgnoreNonTransientErrorTimestampAnnotation : time .Now ().Add (48 * time .Hour ).Format (time .RFC3339 ),
45- }
46- _ , err := instance .ValidateUpdate (instance )
47- Expect (err ).To (HaveOccurred ())
48- })
49- })
5027 })
5128
5229 Context ("Validate Delete" , func () {
@@ -76,94 +53,5 @@ var _ = Describe("Service Instance Webhook Test", func() {
7653 Expect (err ).ToNot (HaveOccurred ())
7754 })
7855 })
79- Context ("Validate Create" , func () {
80- When ("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with not a date" , func () {
81- It ("should not return error from webhook" , func () {
82- instance .Annotations = map [string ]string {
83- common .IgnoreNonTransientErrorAnnotation : "true" ,
84- common .IgnoreNonTransientErrorTimestampAnnotation : "true" ,
85- }
86- _ , err := instance .ValidateCreate ()
87- Expect (err ).To (HaveOccurred ())
88- Expect (err .Error ()).To (ContainSubstring (fmt .Sprintf (annotationNotValidTimestampError , common .IgnoreNonTransientErrorTimestampAnnotation )))
89-
90- })
91- })
92- When ("service instance IgnoreNonTransientErrorTimestampAnnotation annotation is not set with future date" , func () {
93- It ("should not return error from webhook" , func () {
94- instance .Annotations = map [string ]string {
95- common .IgnoreNonTransientErrorAnnotation : "true" ,
96- common .IgnoreNonTransientErrorTimestampAnnotation : time .Now ().Add (48 * time .Hour ).Format (time .RFC3339 ),
97- }
98- _ , err := instance .ValidateCreate ()
99- Expect (err ).To (HaveOccurred ())
100- Expect (err .Error ()).To (ContainSubstring (fmt .Sprintf (annotationInFutureError , common .IgnoreNonTransientErrorTimestampAnnotation )))
101-
102- })
103- })
104- })
105- })
106-
107- Context ("validateNonTransientTimestampAnnotation" , func () {
108- It ("fails when not a valid date" , func () {
109- annotation := map [string ]string {
110- common .IgnoreNonTransientErrorAnnotation : "true" ,
111- common .IgnoreNonTransientErrorTimestampAnnotation : "true" ,
112- }
113- instance .SetAnnotations (annotation )
114- err := instance .validateNonTransientTimestampAnnotation ()
115- Expect (err ).To (HaveOccurred ())
116- Expect (err .Error ()).To (ContainSubstring ("is not a valid timestamp" ))
117- })
118-
119- It ("fails when a future date" , func () {
120- annotation := map [string ]string {
121- common .IgnoreNonTransientErrorAnnotation : "true" ,
122- common .IgnoreNonTransientErrorTimestampAnnotation : time .Now ().Add (48 * time .Hour ).Format (time .RFC3339 ),
123- }
124- instance .SetAnnotations (annotation )
125- err := instance .validateNonTransientTimestampAnnotation ()
126- Expect (err ).To (HaveOccurred ())
127- Expect (err .Error ()).To (ContainSubstring (fmt .Sprintf (annotationInFutureError , common .IgnoreNonTransientErrorTimestampAnnotation )))
128- })
129-
130- It ("succeeds when timestamp is valid and in the past" , func () {
131- annotation := map [string ]string {
132- common .IgnoreNonTransientErrorAnnotation : "true" ,
133- common .IgnoreNonTransientErrorTimestampAnnotation : time .Now ().Format (time .RFC3339 ),
134- }
135- instance .SetAnnotations (annotation )
136- err := instance .validateNonTransientTimestampAnnotation ()
137- Expect (err ).NotTo (HaveOccurred ())
138- })
139- //
140- //It("validate annotation exist and valid", func() {
141- // annotation := map[string]string{
142- // api.IgnoreNonTransientErrorAnnotation: "true",
143- // api.IgnoreNonTransientErrorTimestampAnnotation: time.Now().Format(time.RFC3339),
144- // }
145- // instance.SetAnnotations(annotation)
146- // exist := utils.IsIgnoreNonTransientAnnotationExistAndValid(serviceinstancelog, instance, time.Hour)
147- // Expect(exist).To(BeTrue())
148- //})
149- //
150- //It("validate timeout for Ignore Non Transient Error Annotation", func() {
151- // annotation := map[string]string{
152- // api.IgnoreNonTransientErrorAnnotation: "true",
153- // api.IgnoreNonTransientErrorTimestampAnnotation: time.Now().Truncate(48 * time.Hour).Format(time.RFC3339),
154- // }
155- // instance.SetAnnotations(annotation)
156- // exist := utils.IsIgnoreNonTransientAnnotationExistAndValid(serviceinstancelog, instance, time.Hour)
157- // Expect(exist).To(BeFalse())
158- //})
159- //
160- //It("validate annotation not exist", func() {
161- // annotation := map[string]string{
162- // api.IgnoreNonTransientErrorTimestampAnnotation: time.Now().Format(time.RFC3339),
163- // }
164- // instance.SetAnnotations(annotation)
165- // exist := utils.IsIgnoreNonTransientAnnotationExistAndValid(serviceinstancelog, instance, time.Hour)
166- // Expect(exist).To(BeFalse())
167- //})
16856 })
16957})
0 commit comments