@@ -132,11 +132,12 @@ func TestWebhookSupport(t *testing.T) {
132
132
133
133
t .Log ("By waiting for the catalog to serve its metadata" )
134
134
require .EventuallyWithT (t , func (ct * assert.CollectT ) {
135
- assert .NoError (t , c .Get (context .Background (), types.NamespacedName {Name : extensionCatalog .GetName ()}, extensionCatalog ))
135
+ assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : extensionCatalog .GetName ()}, extensionCatalog ))
136
136
cond := apimeta .FindStatusCondition (extensionCatalog .Status .Conditions , ocv1 .TypeServing )
137
- assert .NotNil (t , cond )
138
- assert .Equal (t , metav1 .ConditionTrue , cond .Status )
139
- assert .Equal (t , ocv1 .ReasonAvailable , cond .Reason )
137
+ if assert .NotNil (ct , cond ) {
138
+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
139
+ assert .Equal (ct , ocv1 .ReasonAvailable , cond .Reason )
140
+ }
140
141
}, pollDuration , pollInterval )
141
142
142
143
t .Log ("By installing the webhook-operator ClusterExtension" )
@@ -173,6 +174,8 @@ func TestWebhookSupport(t *testing.T) {
173
174
assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
174
175
assert .Equal (ct , ocv1 .ReasonSucceeded , cond .Reason )
175
176
assert .Contains (ct , cond .Message , "Installed bundle" )
177
+ }
178
+ if assert .NotNil (ct , clusterExtension .Status .Install ) {
176
179
assert .NotEmpty (ct , clusterExtension .Status .Install .Bundle )
177
180
}
178
181
}, pollDuration , pollInterval )
@@ -197,21 +200,29 @@ func TestWebhookSupport(t *testing.T) {
197
200
}
198
201
v1Client := dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ())
199
202
200
- t .Log ("By checking an invalid CR is rejected by the validating webhook" )
201
- obj := getWebhookOperatorResource ("invalid-test-cr" , namespace .GetName (), false )
202
- _ , err := v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
203
- require .Error (t , err )
204
- require .Contains (t , err .Error (), "Invalid value: false: Spec.Valid must be true" )
203
+ t .Log ("By eventually seeing that invalid CR creation is rejected by the validating webhook" )
204
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
205
+ obj := getWebhookOperatorResource ("invalid-test-cr" , namespace .GetName (), false )
206
+ _ , err := v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
207
+ assert .Error (ct , err )
208
+ assert .Contains (ct , err .Error (), "Invalid value: false: Spec.Valid must be true" )
209
+ }, pollDuration , pollInterval )
210
+
211
+ var (
212
+ res * unstructured.Unstructured
213
+ err error
214
+ obj = getWebhookOperatorResource ("valid-test-cr" , namespace .GetName (), true )
215
+ )
205
216
206
- t .Log ("By checking a valid CR is mutated by the mutating webhook" )
207
- obj = getWebhookOperatorResource ("valid-test-cr" , namespace .GetName (), true )
208
- _ , err = v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
209
- require .NoError (t , err )
217
+ t .Log ("By eventually creating a valid CR" )
218
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
219
+ res , err = v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
220
+ assert .NoError (ct , err )
221
+ }, pollDuration , pollInterval )
210
222
t .Cleanup (func () {
211
- require .NoError (t , dynamicClient . Resource ( v1Gvr ). Namespace ( namespace . GetName ()) .Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
223
+ require .NoError (t , v1Client .Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
212
224
})
213
- res , err := v1Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
214
- require .NoError (t , err )
225
+
215
226
require .Equal (t , map [string ]interface {}{
216
227
"valid" : true ,
217
228
"mutate" : true ,
@@ -225,8 +236,13 @@ func TestWebhookSupport(t *testing.T) {
225
236
}
226
237
v2Client := dynamicClient .Resource (v2Gvr ).Namespace (namespace .GetName ())
227
238
228
- res , err = v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
229
- require .NoError (t , err )
239
+ t .Log ("By eventually getting the valid CR with a v2 client" )
240
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
241
+ res , err = v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
242
+ assert .NoError (ct , err )
243
+ }, pollDuration , pollInterval )
244
+
245
+ t .Log ("and verifying that the CR is correctly converted" )
230
246
require .Equal (t , map [string ]interface {}{
231
247
"conversion" : map [string ]interface {}{
232
248
"valid" : true ,
0 commit comments