@@ -132,11 +132,11 @@ 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+ assert .NotNil (ct , cond )
138+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
139+ assert .Equal (ct , ocv1 .ReasonAvailable , cond .Reason )
140140 }, pollDuration , pollInterval )
141141
142142 t .Log ("By installing the webhook-operator ClusterExtension" )
@@ -169,12 +169,12 @@ func TestWebhookSupport(t *testing.T) {
169169 require .EventuallyWithT (t , func (ct * assert.CollectT ) {
170170 assert .NoError (ct , c .Get (t .Context (), types.NamespacedName {Name : clusterExtension .Name }, clusterExtension ))
171171 cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1 .TypeInstalled )
172- if assert .NotNil (ct , cond ) {
173- assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
174- assert .Equal (ct , ocv1 .ReasonSucceeded , cond .Reason )
175- assert .Contains (ct , cond .Message , "Installed bundle" )
176- assert .NotEmpty (ct , clusterExtension .Status .Install . Bundle )
177- }
172+ assert .NotNil (ct , cond )
173+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
174+ assert .Equal (ct , ocv1 .ReasonSucceeded , cond .Reason )
175+ assert .Contains (ct , cond .Message , "Installed bundle" )
176+ assert .NotNil (ct , clusterExtension .Status .Install )
177+ assert . NotEmpty ( ct , clusterExtension . Status . Install . Bundle )
178178 }, pollDuration , pollInterval )
179179
180180 t .Log ("By waiting for webhook-operator deployment to be available" )
@@ -197,21 +197,29 @@ func TestWebhookSupport(t *testing.T) {
197197 }
198198 v1Client := dynamicClient .Resource (v1Gvr ).Namespace (namespace .GetName ())
199199
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" )
200+ t .Log ("By eventually seeing that invalid CR creation is rejected by the validating webhook" )
201+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
202+ obj := getWebhookOperatorResource ("invalid-test-cr" , namespace .GetName (), false )
203+ _ , err := v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
204+ require .Error (ct , err )
205+ require .Contains (ct , err .Error (), "Invalid value: false: Spec.Valid must be true" )
206+ }, pollDuration , pollInterval )
205207
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 )
208+ var (
209+ res * unstructured.Unstructured
210+ err error
211+ obj = getWebhookOperatorResource ("valid-test-cr" , namespace .GetName (), true )
212+ )
213+
214+ t .Log ("By eventually creating a valid CR" )
215+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
216+ res , err = v1Client .Create (t .Context (), obj , metav1.CreateOptions {})
217+ require .NoError (ct , err )
218+ }, pollDuration , pollInterval )
210219 t .Cleanup (func () {
211- require .NoError (t , dynamicClient . Resource ( v1Gvr ). Namespace ( namespace . GetName ()) .Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
220+ require .NoError (t , v1Client .Delete (context .Background (), obj .GetName (), metav1.DeleteOptions {}))
212221 })
213- res , err := v1Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
214- require .NoError (t , err )
222+
215223 require .Equal (t , map [string ]interface {}{
216224 "valid" : true ,
217225 "mutate" : true ,
@@ -225,8 +233,13 @@ func TestWebhookSupport(t *testing.T) {
225233 }
226234 v2Client := dynamicClient .Resource (v2Gvr ).Namespace (namespace .GetName ())
227235
228- res , err = v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
229- require .NoError (t , err )
236+ t .Log ("By eventually getting the valid CR with a v2 client" )
237+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
238+ res , err = v2Client .Get (t .Context (), obj .GetName (), metav1.GetOptions {})
239+ require .NoError (ct , err )
240+ }, pollDuration , pollInterval )
241+
242+ t .Log ("and verifying that the CR is correctly converted" )
230243 require .Equal (t , map [string ]interface {}{
231244 "conversion" : map [string ]interface {}{
232245 "valid" : true ,
0 commit comments