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

Set target cluster for social events #1035

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/codeready-toolchain/toolchain-e2e

require (
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69 h1:e6up2k4O7QdG6hu0iOwNGap60b932N0JXlweDmmvCAQ=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18 h1:ZSXXcz3BmYvYmw1BexF4xvRjlr/3W5IOKxvc1NwLjKg=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18/go.mod h1:ulg9vY3W6Lsrn84/qVneCIrTvMkBC1mzmQqGfYDv7lQ=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27 h1:uEH8HAM81QZBccuqQpGKJUoJQe28+DFSYi/mRKZDYrA=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a h1:o18wLp3eT4HdH8TvDqtLWiC47WY/kaTp9p54exux/MU=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a/go.mod h1:aIbki5CFsykeqZn2/ZwvUb3Krx2f2Tbq58R6MGnk6H8=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
48 changes: 37 additions & 11 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,15 @@ func TestActivationCodeVerification(t *testing.T) {
t.Parallel()
await := WaitForDeployments(t)
hostAwait := await.Host()
member2Await := await.Member2()
route := hostAwait.RegistrationServiceURL

t.Run("verification successful", func(t *testing.T) {
verifySuccessful := func(t *testing.T, targetCluster string) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
testsocialevent.WithSpaceTier("base1ns6didler"),
testsocialevent.WithTargetCluster(targetCluster))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -728,22 +730,37 @@ func TestActivationCodeVerification(t *testing.T) {
// check that the MUR and Space are configured as expected
// Wait for the UserSignup to have the desired state
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasCompliantUsername())
wait.UntilUserSignupHasCompliantUsername(),
wait.UntilUserSignupHasTargetCluster(targetCluster))
mfrancisc marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
mur, err := hostAwait.WaitForMasterUserRecord(t, userSignup.Status.CompliantUsername,
wait.UntilMasterUserRecordHasTierName(event.Spec.UserTier),
wait.UntilMasterUserRecordHasCondition(wait.Provisioned()))
require.NoError(t, err)
assert.Equal(t, event.Spec.UserTier, mur.Spec.TierName)
_, err = hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername,
spaceCriterion := []wait.SpaceWaitCriterion{
wait.UntilSpaceHasTier(event.Spec.SpaceTier),
wait.UntilSpaceHasConditions(wait.Provisioned()),
)
}
if targetCluster != "" {
spaceCriterion = append(spaceCriterion, wait.UntilSpaceHasStatusTargetCluster(targetCluster))
} else {
spaceCriterion = append(spaceCriterion, wait.UntilSpaceHasAnyTargetClusterSet())
}
_, err = hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername, spaceCriterion...)
require.NoError(t, err)

// also check that the SocialEvent status was updated accordingly
_, err = hostAwait.WaitForSocialEvent(t, event.Name, wait.UntilSocialEventHasActivationCount(1))
require.NoError(t, err)
}

t.Run("verification successful with no target cluster", func(t *testing.T) {
verifySuccessful(t, "")
})

t.Run("verification successful with target cluster", func(t *testing.T) {
verifySuccessful(t, member2Await.ClusterName)
})

t.Run("verification failed", func(t *testing.T) {
Expand All @@ -767,7 +784,8 @@ func TestActivationCodeVerification(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
testsocialevent.WithSpaceTier("base1ns6didler"),
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
event, err = hostAwait.WaitForSocialEvent(t, event.Name) // need to reload event
Expand All @@ -785,14 +803,17 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is not approved yet
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})

t.Run("not opened yet", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(), testsocialevent.WithStartTime(time.Now().Add(time.Hour))) // not open yet
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithStartTime(time.Now().Add(time.Hour)), // not open yet
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -804,14 +825,18 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is not approved yet
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})

t.Run("already closed", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(), testsocialevent.WithEndTime(time.Now().Add(-time.Hour))) // already closd
event := testsocialevent.NewSocialEvent(hostAwait.Namespace,
commonsocialevent.NewName(),
testsocialevent.WithEndTime(time.Now().Add(-time.Hour)), // already closd
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -823,7 +848,8 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is approved
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/parallel/socialevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestCreateSocialEvent(t *testing.T) {
testsocialevent.WithStartTime(start),
testsocialevent.WithEndTime(end),
testsocialevent.WithMaxAttendees(5),
testsocialevent.WithTargetCluster("member-1"),
)

// when
Expand All @@ -51,6 +52,7 @@ func TestCreateSocialEvent(t *testing.T) {
assert.Equal(t, start, event.Spec.StartTime.Time)
assert.Equal(t, end, event.Spec.EndTime.Time)
assert.Equal(t, 5, event.Spec.MaxAttendees)
assert.Equal(t, "member-1", event.Spec.TargetCluster)
})

t.Run("create socialevent with invalid user tier name", func(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,19 @@ func UntilUserSignupHasConditions(expected ...toolchainv1alpha1.Condition) UserS
}
}

// UntilUserSignupHasTargetCluster returns a `UserSignupWaitCriterion` which checks that the given
// UserSignup has the expected target cluster field
func UntilUserSignupHasTargetCluster(expectedTargetCluster string) UserSignupWaitCriterion {
return UserSignupWaitCriterion{
Match: func(actual *toolchainv1alpha1.UserSignup) bool {
return actual.Spec.TargetCluster == expectedTargetCluster
},
Diff: func(actual *toolchainv1alpha1.UserSignup) string {
return fmt.Sprintf("expected target cluster to match:\n%s", Diff(expectedTargetCluster, actual.Spec.TargetCluster))
},
}
}

// UntilUserSignupContainsConditions returns a `UserSignupWaitCriterion` which checks that the given
// UserSignup contains all the given status conditions
func UntilUserSignupContainsConditions(shouldContain ...toolchainv1alpha1.Condition) UserSignupWaitCriterion {
Expand Down
Loading