Skip to content

Commit

Permalink
fix: use SocialEvent's UserTier and SpaceTier when provisioning (#623)
Browse files Browse the repository at this point in the history
Fixes https://issues.redhat.com/browse/CRT-1613

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Co-authored-by: Rajiv Senthilnathan <rajivnathan@gmail.com>
  • Loading branch information
xcoulon and rajivnathan committed Dec 1, 2022
1 parent a15fff4 commit 855cd50
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/codeready-toolchain/toolchain-e2e

require (
github.com/codeready-toolchain/api v0.0.0-20221121081259-4f672e808b89
github.com/codeready-toolchain/toolchain-common v0.0.0-20221117081323-252a38460fa1
github.com/codeready-toolchain/toolchain-common v0.0.0-20221124073251-2d6d8cbd5eb7
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u9
github.com/codeready-toolchain/api v0.0.0-20221102132326-7a7f4eb137db/go.mod h1:gY0608ZR+9w2kLyIdMOD9+fYH4tSCF4G6WrjSBVEUm4=
github.com/codeready-toolchain/api v0.0.0-20221121081259-4f672e808b89 h1:wRwtfj0kAIRTDmRDyE02bnuokbV39ZqfHGxDPMpL9gw=
github.com/codeready-toolchain/api v0.0.0-20221121081259-4f672e808b89/go.mod h1:gY0608ZR+9w2kLyIdMOD9+fYH4tSCF4G6WrjSBVEUm4=
github.com/codeready-toolchain/toolchain-common v0.0.0-20221117081323-252a38460fa1 h1:RIto+kiBO8ZgN22fslwNdzJmXPFgKr084RF5TTu6aC0=
github.com/codeready-toolchain/toolchain-common v0.0.0-20221117081323-252a38460fa1/go.mod h1:A/iDLHUo3elfbgiOZSGWUOsRzPYC9fAdc9W0k5rbUp8=
github.com/codeready-toolchain/toolchain-common v0.0.0-20221124073251-2d6d8cbd5eb7 h1:x3CYxObSLwjLPaRPkauLkudvCO8xFXr8ZAxVQ3dVZDI=
github.com/codeready-toolchain/toolchain-common v0.0.0-20221124073251-2d6d8cbd5eb7/go.mod h1:A/iDLHUo3elfbgiOZSGWUOsRzPYC9fAdc9W0k5rbUp8=
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
27 changes: 24 additions & 3 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ func TestActivationCodeVerification(t *testing.T) {

t.Run("verification successful", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName())
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
err := hostAwait.CreateWithCleanup(context.TODO(), event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -613,7 +615,24 @@ func TestActivationCodeVerification(t *testing.T) {
states.SetApprovedManually(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' reactivated", userSignup.Name)
t.Logf("user signup '%s' approved", userSignup.Name)

// check that the MUR and Space are configured as expected
// Wait for the UserSignup to have the desired state
userSignup, err = hostAwait.WaitForUserSignup(userSignup.Name,
wait.UntilUserSignupHasCompliantUsername())
require.NoError(t, err)
mur, err := hostAwait.WaitForMasterUserRecord(userSignup.Status.CompliantUsername,
wait.UntilMasterUserRecordHasTierName(event.Spec.UserTier),
wait.UntilMasterUserRecordHasCondition(Provisioned()))
require.NoError(t, err)
assert.Equal(t, event.Spec.UserTier, mur.Spec.TierName)
_, err = hostAwait.WaitForSpace(userSignup.Status.CompliantUsername,
wait.UntilSpaceHasTier(event.Spec.SpaceTier),
wait.UntilSpaceHasConditions(Provisioned()),
)
require.NoError(t, err)

// also check that the SocialEvent status was updated accordingly
_, err = hostAwait.WaitForSocialEvent(event.Name, wait.UntilSocialEventHasActivationCount(1))
require.NoError(t, err)
Expand All @@ -638,7 +657,9 @@ func TestActivationCodeVerification(t *testing.T) {

t.Run("over capacity", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName())
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
err := hostAwait.CreateWithCleanup(context.TODO(), event)
require.NoError(t, err)
event, err = hostAwait.WaitForSocialEvent(event.Name) // need to reload event
Expand Down
56 changes: 37 additions & 19 deletions test/e2e/parallel/socialevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package parallel
import (
"context"
"testing"
"time"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
commonsocialevent "github.com/codeready-toolchain/toolchain-common/pkg/socialevent"
testsocialevent "github.com/codeready-toolchain/toolchain-common/pkg/test/socialevent"
"github.com/codeready-toolchain/toolchain-e2e/testsupport"
. "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -20,34 +24,47 @@ func TestCreateSocialEvent(t *testing.T) {
awaitilities := testsupport.WaitForDeployments(t)
hostAwait := awaitilities.Host()

t.Run("create socialevent with valid tiername", func(t *testing.T) {
t.Run("create socialevent with custom settings", func(t *testing.T) {
// given
name := testsupport.GenerateName("lab")
se := testsupport.NewSocialEvent(hostAwait.Namespace, name, "deactivate30", "base")
start := time.Now().Add(time.Hour).Round(time.Second)
end := time.Now().Add(24 * time.Hour).Round(time.Second)
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate30"),
testsocialevent.WithSpaceTier("base1ns"),
testsocialevent.WithStartTime(start),
testsocialevent.WithEndTime(end),
testsocialevent.WithMaxAttendees(5),
)

// when
err := hostAwait.CreateWithCleanup(context.TODO(), se)
err := hostAwait.CreateWithCleanup(context.TODO(), event)

// then
require.NoError(t, err)
_, err = hostAwait.WaitForSocialEvent(name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
event, err = hostAwait.WaitForSocialEvent(event.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
}))
require.NoError(t, err)
assert.Equal(t, "deactivate30", event.Spec.UserTier)
assert.Equal(t, "base1ns", event.Spec.SpaceTier)
assert.Equal(t, start, event.Spec.StartTime.Time)
assert.Equal(t, end, event.Spec.EndTime.Time)
assert.Equal(t, 5, event.Spec.MaxAttendees)
})

t.Run("create socialevent with invalid user tier name", func(t *testing.T) {
// given
name := testsupport.GenerateName("lab")
se := testsupport.NewSocialEvent(hostAwait.Namespace, name, "invalid", "base")
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("invalid"),
testsocialevent.WithSpaceTier("base1ns"))

// when
err := hostAwait.CreateWithCleanup(context.TODO(), se)
err := hostAwait.CreateWithCleanup(context.TODO(), event)

// then
require.NoError(t, err)
se, err = hostAwait.WaitForSocialEvent(name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
event, err = hostAwait.WaitForSocialEvent(event.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Reason: toolchainv1alpha1.SocialEventInvalidUserTierReason,
Expand All @@ -57,14 +74,14 @@ func TestCreateSocialEvent(t *testing.T) {

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

// when
err := hostAwait.Client.Update(context.TODO(), se)
err := hostAwait.Client.Update(context.TODO(), event)

// then
require.NoError(t, err)
_, err = hostAwait.WaitForSocialEvent(se.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
_, err = hostAwait.WaitForSocialEvent(event.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
}))
Expand All @@ -74,15 +91,16 @@ func TestCreateSocialEvent(t *testing.T) {

t.Run("create socialevent with invalid space tier name", func(t *testing.T) {
// given
name := testsupport.GenerateName("lab")
se := testsupport.NewSocialEvent(hostAwait.Namespace, name, "deactivate30", "invalid")
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate30"),
testsocialevent.WithSpaceTier("invalid"))

// when
err := hostAwait.CreateWithCleanup(context.TODO(), se)
err := hostAwait.CreateWithCleanup(context.TODO(), event)

// then
require.NoError(t, err)
se, err = hostAwait.WaitForSocialEvent(name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
event, err = hostAwait.WaitForSocialEvent(event.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Reason: toolchainv1alpha1.SocialEventInvalidSpaceTierReason,
Expand All @@ -92,14 +110,14 @@ func TestCreateSocialEvent(t *testing.T) {

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

// when
err := hostAwait.Client.Update(context.TODO(), se)
err := hostAwait.Client.Update(context.TODO(), event)

// then
require.NoError(t, err)
_, err = hostAwait.WaitForSocialEvent(se.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
_, err = hostAwait.WaitForSocialEvent(event.Name, UntilSocialEventHasConditions(toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
}))
Expand Down
13 changes: 13 additions & 0 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,19 @@ func UntilUserSignupHasStateLabel(expected string) UserSignupWaitCriterion {
}
}

// UntilUserSignupHasCompliantUsername returns a `UserSignupWaitCriterion` which checks that the given
// UserSignup has a `.Status.CompliantUsername` value
func UntilUserSignupHasCompliantUsername() UserSignupWaitCriterion {
return UserSignupWaitCriterion{
Match: func(actual *toolchainv1alpha1.UserSignup) bool {
return actual.Status.CompliantUsername != ""
},
Diff: func(actual *toolchainv1alpha1.UserSignup) string {
return "expected to have a value for '.Status.CompliantUsername'"
},
}
}

// WaitForTestResourcesCleanup waits for all UserSignup, MasterUserRecord, Space, SpaceBinding, NSTemplateSet and Namespace deletions to complete
func (a *HostAwaitility) WaitForTestResourcesCleanup(initialDelay time.Duration) error {
a.T.Logf("waiting for resource cleanup")
Expand Down

0 comments on commit 855cd50

Please sign in to comment.