Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SANDBOX-838: loop update calls #1074

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/e2e/no_user_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func TestCreationOfUserAndIdentityIsSkipped(t *testing.T) {

t.Run("user and identity stay there when user is deactivated", func(t *testing.T) {
// when
userSignup, err := hostAwait.UpdateUserSignup(t, signup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
userSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(signup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)

// Wait until the UserSignup is deactivated
Expand Down
21 changes: 13 additions & 8 deletions test/e2e/parallel/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ func TestE2EFlow(t *testing.T) {
require.NoError(t, err)

// when
user.Identities = []string{}
err = memberAwait.Client.Update(context.TODO(), user)
_, err = wait.For(t, memberAwait.Awaitility, &userv1.User{}).
Update(user.Name, func(u *userv1.User) {
u.Identities = []string{}
})

// then
require.NoError(t, err)
Expand All @@ -175,10 +177,12 @@ func TestE2EFlow(t *testing.T) {
err := memberAwait.Client.Get(context.TODO(), types.NamespacedName{Name: identitypkg.NewIdentityNamingStandard(
johnSignup.Spec.IdentityClaims.Sub, "rhd").IdentityName()}, identity)
require.NoError(t, err)
identity.User = corev1.ObjectReference{Name: "", UID: ""}

// when
err = memberAwait.Client.Update(context.TODO(), identity)
_, err = wait.For(t, memberAwait.Awaitility, &userv1.Identity{}).
Update(identity.Name, func(i *userv1.Identity) {
i.User = corev1.ObjectReference{Name: "", UID: ""}
})

// then
require.NoError(t, err)
Expand Down Expand Up @@ -483,10 +487,11 @@ func TestE2EFlow(t *testing.T) {
require.Len(t, userList.Items, 1)

// Now deactivate the UserSignup
userSignup, err := hostAwait.UpdateUserSignup(t, originalSubJohnSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
userSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(originalSubJohnSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)

// Wait until the UserSignup is deactivated
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/parallel/nstemplatetier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ func TestResetDeactivatingStateWhenPromotingUser(t *testing.T) {
RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin())...).
Execute(t)
// Set the deactivating state on the UserSignup
updatedUserSignup, err := hostAwait.UpdateUserSignup(t, user.UserSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivating(us, true)
})
updatedUserSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(user.UserSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivating(us, true)
})
require.NoError(t, err)

// Move the MUR to the user tier with longer deactivation time
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/parallel/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
rbacv1 "k8s.io/api/rbac/v1"
"net/http"
"net/url"
"os"
Expand All @@ -18,6 +17,8 @@ import (
"testing"
"time"

rbacv1 "k8s.io/api/rbac/v1"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
commonproxy "github.com/codeready-toolchain/toolchain-common/pkg/proxy"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
Expand Down
60 changes: 34 additions & 26 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,13 @@ func TestSignupOK(t *testing.T) {
identity.ID, identity.Username), mp["message"])
assert.Equal(t, "error creating UserSignup resource", mp["details"])

userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Approve usersignup.
states.SetApprovedManually(instance, true)
instance.Spec.TargetCluster = memberAwait.ClusterName
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Approve usersignup.
states.SetApprovedManually(instance, true)
instance.Spec.TargetCluster = memberAwait.ClusterName
})
require.NoError(t, err)

// Wait for the resources to be provisioned
Expand All @@ -444,10 +445,11 @@ func TestSignupOK(t *testing.T) {
t.Logf("Signed up new user %+v", userSignup)

// Deactivate the usersignup
userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)
_, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.DeactivatedWithoutPreDeactivation())...),
Expand Down Expand Up @@ -609,11 +611,12 @@ func TestPhoneVerification(t *testing.T) {
assert.Equal(t, "PendingApproval", mpStatus["reason"])
require.False(t, mpStatus["verificationRequired"].(bool))

userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Now approve the usersignup.
states.SetApprovedManually(instance, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Now approve the usersignup.
states.SetApprovedManually(instance, true)
})
require.NoError(t, err)
transformedUsername := commonsignup.TransformUsername(userSignup.Spec.IdentityClaims.PreferredUsername, []string{"openshift", "kube", "default", "redhat", "sandbox"}, []string{"admin"})
// Confirm the MasterUserRecord is provisioned
Expand Down Expand Up @@ -666,11 +669,12 @@ func TestPhoneVerification(t *testing.T) {
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name)
require.NoError(t, err)

userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Now mark the original UserSignup as deactivated
states.SetDeactivated(instance, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(instance *toolchainv1alpha1.UserSignup) {
// Now mark the original UserSignup as deactivated
states.SetDeactivated(instance, true)
})
require.NoError(t, err)

// Ensure the UserSignup is deactivated
Expand Down Expand Up @@ -720,10 +724,11 @@ func TestActivationCodeVerification(t *testing.T) {
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.PendingApproval())...))
require.NoError(t, err)
// explicitly approve the usersignup (see above, config for parallel test has automatic approval disabled)
userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(us, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' approved", userSignup.Name)

Expand Down Expand Up @@ -793,8 +798,11 @@ func TestActivationCodeVerification(t *testing.T) {
Status: corev1.ConditionTrue,
})) // need to reload event
require.NoError(t, err)
event.Status.ActivationCount = event.Spec.MaxAttendees // activation count identical to `MaxAttendees`
err = hostAwait.Client.Status().Update(context.TODO(), event)
event, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.SocialEvent{}).
UpdateStatus(event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Status.ActivationCount = event.Spec.MaxAttendees // activation count identical to `MaxAttendees`
})
require.NoError(t, err)

userSignup, token := signup(t, hostAwait)
Expand Down
19 changes: 10 additions & 9 deletions test/e2e/parallel/socialevent_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package parallel

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -75,11 +74,12 @@ func TestCreateSocialEvent(t *testing.T) {
require.NoError(t, err)

t.Run("update with valid tier name", func(t *testing.T) {
// given
event.Spec.UserTier = "deactivate30"

// when
err := hostAwait.Client.Update(context.TODO(), event)
event, err = For(t, hostAwait.Awaitility, &toolchainv1alpha1.SocialEvent{}).
Update(event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Spec.UserTier = "deactivate30"
})

// then
require.NoError(t, err)
Expand Down Expand Up @@ -111,11 +111,12 @@ func TestCreateSocialEvent(t *testing.T) {
require.NoError(t, err)

t.Run("update with valid tier name", func(t *testing.T) {
// given
event.Spec.SpaceTier = "base"

// when
err := hostAwait.Client.Update(context.TODO(), event)
event, err = For(t, hostAwait.Awaitility, &toolchainv1alpha1.SocialEvent{}).
Update(event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Spec.SpaceTier = "base"
})

// then
require.NoError(t, err)
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/parallel/space_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ func TestSpaceAndSpaceBindingCleanup(t *testing.T) {

// when
// deactivate the UserSignup so that the MUR will be deleted
userSignup, err := hostAwait.UpdateUserSignup(t, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
userSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' set to deactivated", userSignup.Name)

Expand All @@ -74,10 +75,11 @@ func TestSpaceAndSpaceBindingCleanup(t *testing.T) {

// when
// we deactivate the UserSignup so that the MUR will be deleted
userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' set to deactivated", userSignup.Name)

Expand Down
25 changes: 12 additions & 13 deletions test/e2e/parallel/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ func TestSpaceRoles(t *testing.T) {
})

t.Run("set owner user as maintainer instead", func(t *testing.T) {
// given an appstudio space with `owner` user as an admin of it
ownerBinding.Spec.SpaceRole = "maintainer"

// when
err = hostAwait.Client.Update(context.TODO(), ownerBinding)
ownerBinding, err = hostAwait.UpdateSpaceBinding(t, ownerBinding.Name, func(sb *toolchainv1alpha1.SpaceBinding) {
// given an appstudio space with `owner` user as an admin of it
sb.Spec.SpaceRole = "maintainer"
})
require.NoError(t, err)

// then
Expand All @@ -222,11 +222,11 @@ func TestSpaceRoles(t *testing.T) {
})

t.Run("set owner user as contributor instead", func(t *testing.T) {
// given an appstudio space with `owner` user as an admin of it
ownerBinding.Spec.SpaceRole = "contributor"

// when
err := hostAwait.Client.Update(context.TODO(), ownerBinding)
ownerBinding, err = hostAwait.UpdateSpaceBinding(t, ownerBinding.Name, func(sb *toolchainv1alpha1.SpaceBinding) {
mfrancisc marked this conversation as resolved.
Show resolved Hide resolved
// given an appstudio space with `owner` user as an admin of it
sb.Spec.SpaceRole = "contributor"
})

// then
require.NoError(t, err)
Expand Down Expand Up @@ -335,13 +335,12 @@ func TestSubSpaces(t *testing.T) {
require.NoError(t, err)

t.Run("we update role in parentSpaceBinding and expect change to be reflected in subSpaces", func(t *testing.T) {
// given
// the parentSpace role was "downgraded" to maintainer
parentSpaceBindings.Spec.SpaceRole = "maintainer"

// when
// we update the parentSpace bindings
err := hostAwait.Client.Update(context.TODO(), parentSpaceBindings)
parentSpaceBindings, err = hostAwait.UpdateSpaceBinding(t, parentSpaceBindings.Name, func(sb *toolchainv1alpha1.SpaceBinding) {
// the parentSpace role was "downgraded" to maintainer
sb.Spec.SpaceRole = "maintainer"
})

// then
// downgrade of the usernames is done in parentSpace
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/parallel/usersignup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func TestTransformUsernameWithSpaceConflict(t *testing.T) {
}()

// now deactivate the usersignup
_, err = hostAwait.UpdateUserSignup(t, userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
_, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)

// wait until it is deactivated, SpaceBinding is gone, and Space is in terminating state
Expand All @@ -81,9 +82,10 @@ func TestTransformUsernameWithSpaceConflict(t *testing.T) {
require.NoError(t, err)

// when
userSignup, err = hostAwait.UpdateUserSignup(t, userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(us, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(us, true)
})
require.NoError(t, err)

// then
Expand Down
Loading
Loading