Skip to content

Commit

Permalink
fix WaitForBannedUser
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoaresd committed Dec 3, 2024
1 parent 91404c7 commit 664fc64
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 664fc64

Please sign in to comment.