From 664fc641e296c90655773736821b6b759befd185 Mon Sep 17 00:00:00 2001 From: Rafaela Soares Date: Tue, 3 Dec 2024 19:08:00 +0000 Subject: [PATCH 1/4] fix WaitForBannedUser --- testsupport/wait/host.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 9852429d3..a0991fee6 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -13,7 +13,6 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/condition" - "github.com/codeready-toolchain/toolchain-common/pkg/hash" "github.com/codeready-toolchain/toolchain-common/pkg/spacebinding" "github.com/codeready-toolchain/toolchain-common/pkg/test" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" @@ -770,24 +769,27 @@ func (a *HostAwaitility) WaitAndVerifyThatUserSignupIsNotCreated(t *testing.T, n } // WaitForBannedUser waits until there is a BannedUser available with the given email -func (a *HostAwaitility) WaitForBannedUser(t *testing.T, email string) (*toolchainv1alpha1.BannedUser, error) { - t.Logf("waiting for BannedUser for user '%s' in namespace '%s'", email, a.Namespace) +// for now, just used for WA +func (a *HostAwaitility) WaitForBannedUser(t *testing.T, userEmailHash string) (*toolchainv1alpha1.BannedUser, error) { + t.Logf("waiting for BannedUser for user '%s' in namespace '%s'", userEmailHash, a.Namespace) var bannedUser *toolchainv1alpha1.BannedUser - labels := map[string]string{toolchainv1alpha1.BannedUserEmailHashLabelKey: hash.EncodeString(email)} + emailHashLabelMatch := client.MatchingLabels(map[string]string{ + toolchainv1alpha1.BannedUserEmailHashLabelKey: userEmailHash, + }) err := wait.PollUntilContextTimeout(context.TODO(), a.RetryInterval, a.Timeout, true, func(ctx context.Context) (done bool, err error) { bannedUserList := &toolchainv1alpha1.BannedUserList{} - if err = a.Client.List(context.TODO(), bannedUserList, client.MatchingLabels(labels), client.InNamespace(a.Namespace)); err != nil { - if len(bannedUserList.Items) == 0 { - return false, nil - } + if err := a.Client.List(ctx, bannedUserList, emailHashLabelMatch, client.InNamespace(a.Namespace)); err != nil { return false, err } - bannedUser = &bannedUserList.Items[0] - return true, nil + if len(bannedUserList.Items) > 0 { + bannedUser = &bannedUserList.Items[0] + return true, nil + } + return false, nil }) // log message if an error occurred if err != nil { - t.Logf("failed to find Banned for email address '%s': %v", email, err) + t.Logf("failed to find Banned for email address '%s': %v", userEmailHash, err) } return bannedUser, err } From 28316e420c13d77ac265acf99f162471d7e37056 Mon Sep 17 00:00:00 2001 From: Rafaela Soares Date: Tue, 3 Dec 2024 19:11:18 +0000 Subject: [PATCH 2/4] update comment --- testsupport/wait/host.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index a0991fee6..84a5c48da 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -769,7 +769,7 @@ func (a *HostAwaitility) WaitAndVerifyThatUserSignupIsNotCreated(t *testing.T, n } // WaitForBannedUser waits until there is a BannedUser available with the given email -// for now, just used for WA +// !!! WARNING: for now, just used for WA func (a *HostAwaitility) WaitForBannedUser(t *testing.T, userEmailHash string) (*toolchainv1alpha1.BannedUser, error) { t.Logf("waiting for BannedUser for user '%s' in namespace '%s'", userEmailHash, a.Namespace) var bannedUser *toolchainv1alpha1.BannedUser From 57a568e12af51f521921b1fdaaf5e4ab85890d34 Mon Sep 17 00:00:00 2001 From: Rafaela Soares Date: Wed, 4 Dec 2024 10:35:30 +0000 Subject: [PATCH 3/4] requested change --- testsupport/wait/host.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 84a5c48da..9f78926b0 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -768,7 +768,7 @@ func (a *HostAwaitility) WaitAndVerifyThatUserSignupIsNotCreated(t *testing.T, n } } -// WaitForBannedUser waits until there is a BannedUser available with the given email +// WaitForBannedUser waits until there is a BannedUser available with the given email hash // !!! WARNING: for now, just used for WA func (a *HostAwaitility) WaitForBannedUser(t *testing.T, userEmailHash string) (*toolchainv1alpha1.BannedUser, error) { t.Logf("waiting for BannedUser for user '%s' in namespace '%s'", userEmailHash, a.Namespace) From 5298f1ef14d263423fde46861339aa74e4f78cd9 Mon Sep 17 00:00:00 2001 From: Rafaela Soares Date: Wed, 4 Dec 2024 12:15:05 +0000 Subject: [PATCH 4/4] improve comments --- testsupport/wait/host.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 9f78926b0..37b847f4c 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -771,7 +771,7 @@ func (a *HostAwaitility) WaitAndVerifyThatUserSignupIsNotCreated(t *testing.T, n // WaitForBannedUser waits until there is a BannedUser available with the given email hash // !!! WARNING: for now, just used for WA func (a *HostAwaitility) WaitForBannedUser(t *testing.T, userEmailHash string) (*toolchainv1alpha1.BannedUser, error) { - t.Logf("waiting for BannedUser for user '%s' in namespace '%s'", userEmailHash, a.Namespace) + t.Logf("waiting for BannedUser for user email hash '%s' in namespace '%s'", userEmailHash, a.Namespace) var bannedUser *toolchainv1alpha1.BannedUser emailHashLabelMatch := client.MatchingLabels(map[string]string{ toolchainv1alpha1.BannedUserEmailHashLabelKey: userEmailHash, @@ -789,7 +789,7 @@ func (a *HostAwaitility) WaitForBannedUser(t *testing.T, userEmailHash string) ( }) // log message if an error occurred if err != nil { - t.Logf("failed to find Banned for email address '%s': %v", userEmailHash, err) + t.Logf("failed to find Banned for email hash '%s': %v", userEmailHash, err) } return bannedUser, err }