Skip to content

Commit

Permalink
add generic update
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoaresd committed Dec 2, 2024
1 parent 88cfeb7 commit b7cd532
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 274 deletions.
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, false, 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
23 changes: 13 additions & 10 deletions test/e2e/parallel/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ func TestE2EFlow(t *testing.T) {
require.NoError(t, err)

// when
_, err = memberAwait.UpdateUser(t, user.Name, func(u *userv1.User) {
u.Identities = []string{}
})
_, 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 @@ -178,9 +179,10 @@ func TestE2EFlow(t *testing.T) {
require.NoError(t, err)

// when
_, err = memberAwait.UpdateIdentity(t, identity.Name, func(i *userv1.Identity) {
i.User = corev1.ObjectReference{Name: "", UID: ""}
})
_, 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 @@ -485,10 +487,11 @@ func TestE2EFlow(t *testing.T) {
require.Len(t, userList.Items, 1)

// Now deactivate the UserSignup
userSignup, err := hostAwait.UpdateUserSignup(t, false, 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, false, 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
62 changes: 34 additions & 28 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, false, 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, false, 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, false, 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, false, 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, false, 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,10 +798,11 @@ func TestActivationCodeVerification(t *testing.T) {
Status: corev1.ConditionTrue,
})) // need to reload event
require.NoError(t, err)
event, err = hostAwait.UpdateSocialEvent(t, true, event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Status.ActivationCount = event.Spec.MaxAttendees // activation count identical to `MaxAttendees`
})
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
18 changes: 10 additions & 8 deletions test/e2e/parallel/socialevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func TestCreateSocialEvent(t *testing.T) {

t.Run("update with valid tier name", func(t *testing.T) {
// when
event, err = hostAwait.UpdateSocialEvent(t, false, event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Spec.UserTier = "deactivate30"
})
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,10 +112,11 @@ func TestCreateSocialEvent(t *testing.T) {

t.Run("update with valid tier name", func(t *testing.T) {
// when
event, err = hostAwait.UpdateSocialEvent(t, false, event.Name,
func(ev *toolchainv1alpha1.SocialEvent) {
ev.Spec.SpaceTier = "base"
})
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, false, 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, false, 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
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, false, 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, false, 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
44 changes: 24 additions & 20 deletions test/e2e/user_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ func (s *userManagementTestSuite) TestUserDeactivation() {
Execute(t)

// Delete the user's email and set them to deactivated
userSignup, err := hostAwait.UpdateUserSignup(t, false, uNoEmail.UserSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
us.Spec.IdentityClaims.Email = ""
states.SetDeactivated(us, true)
})
userSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(uNoEmail.UserSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
us.Spec.IdentityClaims.Email = ""
states.SetDeactivated(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' set to deactivated", userSignup.Name)

Expand Down Expand Up @@ -499,10 +500,11 @@ func (s *userManagementTestSuite) TestUserDeactivation() {
require.NoError(t, err)

// Now deactivate the user
userSignup, err = hostAwait.UpdateUserSignup(t, false, 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)

userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
Expand All @@ -516,13 +518,14 @@ func (s *userManagementTestSuite) TestUserDeactivation() {
testconfig.Deactivation().UserSignupUnverifiedRetentionDays(0))

// Reactivate the user
userSignup, err = hostAwait.UpdateUserSignup(t, false, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivating(us, false)
states.SetDeactivated(us, false)
states.SetApprovedManually(us, true)
states.SetVerificationRequired(us, true)
})
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivating(us, false)
states.SetDeactivated(us, false)
states.SetApprovedManually(us, true)
states.SetVerificationRequired(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' reactivated", userSignup.Name)

Expand Down Expand Up @@ -781,10 +784,11 @@ func (s *userManagementTestSuite) TestReturningUsersProvisionedToLastCluster() {
// when
DeactivateAndCheckUser(t, s.Awaitilities, userSignup)
// If TargetCluster is set it will override the last cluster annotation so remove TargetCluster
userSignup, err := s.Host().UpdateUserSignup(t, false, userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
us.Spec.TargetCluster = ""
})
userSignup, err := wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name,
func(us *toolchainv1alpha1.UserSignup) {
us.Spec.TargetCluster = ""
})
require.NoError(t, err)

ReactivateAndCheckUser(t, s.Awaitilities, userSignup)
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/usersignup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,11 @@ func (s *userSignupIntegrationTest) TestUserResourcesUpdatedWhenPropagatedClaims
VerifyResourcesProvisionedForSignup(s.T(), s.Awaitilities, userSignup)

// Update the UserSignup
userSignup, err := hostAwait.UpdateUserSignup(s.T(), false, userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
// Modify the user's AccountID
us.Spec.IdentityClaims.AccountID = "nnnbbb111234"
})
userSignup, err := wait.For(s.T(), hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name, func(us *toolchainv1alpha1.UserSignup) {
// Modify the user's AccountID
us.Spec.IdentityClaims.AccountID = "nnnbbb111234"
})
require.NoError(s.T(), err)

// Confirm the AccountID is updated
Expand Down
Loading

0 comments on commit b7cd532

Please sign in to comment.