@@ -132,11 +132,12 @@ func TestWebhookSupport(t *testing.T) {
132132
133133 t .Log ("By waiting for the catalog to serve its metadata" )
134134 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 ))
136136 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+ }
140141 }, pollDuration , pollInterval )
141142
142143 t .Log ("By installing the webhook-operator ClusterExtension" )
@@ -173,7 +174,9 @@ func TestWebhookSupport(t *testing.T) {
173174 assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
174175 assert .Equal (ct , ocv1 .ReasonSucceeded , cond .Reason )
175176 assert .Contains (ct , cond .Message , "Installed bundle" )
176- assert .NotEmpty (ct , clusterExtension .Status .Install .Bundle )
177+ if assert .NotNil (ct , clusterExtension .Status .Install ) {
178+ assert .NotEmpty (ct , clusterExtension .Status .Install .Bundle )
179+ }
177180 }
178181 }, pollDuration , pollInterval )
179182
@@ -198,24 +201,28 @@ func TestWebhookSupport(t *testing.T) {
198201 v1Client := dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ())
199202
200203 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" )
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+ require .Error (ct , err )
208+ require .Contains (ct , err .Error (), "Invalid value: false: Spec.Valid must be true" )
209+ }, pollDuration , pollInterval )
205210
206211 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 )
210- t .Cleanup (func () {
211- require .NoError (t , dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ()).Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
212- })
213- res , err := v1Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
214- require .NoError (t , err )
215- require .Equal (t , map [string ]interface {}{
216- "valid" : true ,
217- "mutate" : true ,
218- }, res .Object ["spec" ])
212+ obj := getWebhookOperatorResource ("valid-test-cr" , namespace .GetName (), true )
213+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
214+ _ , err := v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
215+ require .NoError (ct , err )
216+ t .Cleanup (func () {
217+ require .NoError (t , dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ()).Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
218+ })
219+ res , err := v1Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
220+ require .NoError (ct , err )
221+ require .Equal (ct , map [string ]interface {}{
222+ "valid" : true ,
223+ "mutate" : true ,
224+ }, res .Object ["spec" ])
225+ }, pollDuration , pollInterval )
219226
220227 t .Log ("By checking a valid CR is converted to v2 by the conversion webhook" )
221228 v2Gvr := schema.GroupVersionResource {
@@ -225,14 +232,16 @@ func TestWebhookSupport(t *testing.T) {
225232 }
226233 v2Client := dynamicClient .Resource (v2Gvr ).Namespace (namespace .GetName ())
227234
228- res , err = v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
229- require .NoError (t , err )
230- require .Equal (t , map [string ]interface {}{
231- "conversion" : map [string ]interface {}{
232- "valid" : true ,
233- "mutate" : true ,
234- },
235- }, res .Object ["spec" ])
235+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
236+ res , err := v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
237+ require .NoError (ct , err )
238+ require .Equal (ct , map [string ]interface {}{
239+ "conversion" : map [string ]interface {}{
240+ "valid" : true ,
241+ "mutate" : true ,
242+ },
243+ }, res .Object ["spec" ])
244+ }, pollDuration , pollInterval )
236245}
237246
238247func getWebhookOperatorResource (name string , namespace string , valid bool ) * unstructured.Unstructured {
0 commit comments