From 3096a87d59f9dc44285e80893cc1f21ce5b3750b Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Fri, 20 Mar 2026 12:57:05 +0100 Subject: [PATCH] Fix flaking TestImpersonation TestImpersonation used require.NoError within require.Eventually, meaning if the user is not immediately able to access the workspace the test fails. Signed-off-by: Nelo-T. Wallus Signed-off-by: Nelo-T. Wallus --- test/e2e/authorizer/impersonate_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/e2e/authorizer/impersonate_test.go b/test/e2e/authorizer/impersonate_test.go index efbc06c6d97..4f677bdb767 100644 --- a/test/e2e/authorizer/impersonate_test.go +++ b/test/e2e/authorizer/impersonate_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" authenticationv1 "k8s.io/api/authentication/v1" @@ -62,13 +63,13 @@ func TestImpersonation(t *testing.T) { t.Logf("User-1 should not be able to edit workspace status") var ws *tenancyv1alpha1.Workspace - require.Eventually(t, func() bool { + require.EventuallyWithT(t, func(c *assert.CollectT) { var err error ws, err = user1Client.TenancyV1alpha1().Workspaces().Cluster(org).Get(ctx, wsObj.Name, metav1.GetOptions{}) - require.NoError(t, err) + require.NoError(c, err) ws.Status.Phase = "Scheduling" _, err = user1Client.TenancyV1alpha1().Workspaces().Cluster(org).UpdateStatus(ctx, ws, metav1.UpdateOptions{}) - return apierrors.IsForbidden(err) + require.True(c, apierrors.IsForbidden(err)) }, wait.ForeverTestTimeout, time.Millisecond*100, "user-1 should not be able to edit its own workspace status") user1Cfg.Impersonate = rest.ImpersonationConfig{ @@ -79,10 +80,10 @@ func TestImpersonation(t *testing.T) { require.NoError(t, err) t.Logf("User-1 should NOT be able to edit workspace status with system:masters impersonation") - require.Eventually(t, func() bool { + require.EventuallyWithT(t, func(c *assert.CollectT) { ws.Status.Phase = "Scheduling" _, err = user1Client.TenancyV1alpha1().Workspaces().Cluster(org).UpdateStatus(ctx, ws, metav1.UpdateOptions{}) - return apierrors.IsForbidden(err) + require.True(c, apierrors.IsForbidden(err)) }, wait.ForeverTestTimeout, time.Millisecond*100, "user-1 should NOT be able to edit its own workspace status with impersonation") }