@@ -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,6 +174,8 @@ 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" )
177+ }
178+ if assert .NotNil (ct , clusterExtension .Status .Install ) {
176179 assert .NotEmpty (ct , clusterExtension .Status .Install .Bundle )
177180 }
178181 }, pollDuration , pollInterval )
@@ -197,21 +200,29 @@ func TestWebhookSupport(t *testing.T) {
197200 }
198201 v1Client := dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ())
199202
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+ )
205216
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 )
210222 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 {}))
212224 })
213- res , err := v1Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
214- require .NoError (t , err )
225+
215226 require .Equal (t , map [string ]interface {}{
216227 "valid" : true ,
217228 "mutate" : true ,
@@ -225,8 +236,13 @@ func TestWebhookSupport(t *testing.T) {
225236 }
226237 v2Client := dynamicClient .Resource (v2Gvr ).Namespace (namespace .GetName ())
227238
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" )
230246 require .Equal (t , map [string ]interface {}{
231247 "conversion" : map [string ]interface {}{
232248 "valid" : true ,
0 commit comments