Skip to content

Commit

Permalink
tests: fix CRD validation test suite (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Jan 22, 2025
1 parent 8cc1c38 commit f3076ec
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/crdsvalidation/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,24 @@ func (tc *TestCase[T]) RunWithConfig(t *testing.T, cfg *rest.Config, scheme *run

assert.EventuallyWithT(t,
func(c *assert.CollectT) {
toCreate := tc.TestObject.DeepCopyObject().(T)

// Create the object and set a cleanup function to delete it after the test if created successfully.
err = cl.Create(ctx, tc.TestObject)
err = cl.Create(ctx, toCreate)
if err == nil {
tCleanupObject(ctx, t, tc.TestObject)
tCleanupObject(ctx, t, toCreate)
}

// If the error message is expected, check if the error message contains the expected message and return.
if tc.ExpectedErrorMessage != nil {
if assert.NotNil(c, err) {
assert.Contains(c, err.Error(), *tc.ExpectedErrorMessage)
if !assert.NotNil(c, err) {
return
}
if !assert.Contains(c, err.Error(), *tc.ExpectedErrorMessage) {
return
}
}
tc.TestObject = toCreate
},
timeout, period,
)
Expand Down

0 comments on commit f3076ec

Please sign in to comment.