From f3076ec12d58374e304b8ec16651f9d601d409fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Wed, 22 Jan 2025 09:12:53 +0100 Subject: [PATCH] tests: fix CRD validation test suite (#247) --- test/crdsvalidation/testcase.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/crdsvalidation/testcase.go b/test/crdsvalidation/testcase.go index 0cb6668..6b971f2 100644 --- a/test/crdsvalidation/testcase.go +++ b/test/crdsvalidation/testcase.go @@ -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, )