diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 0618db8a5..03d518a23 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -12,6 +12,7 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" diff --git a/test/e2e/nstemplatetier_test.go b/test/e2e/nstemplatetier_test.go index 77aafb188..417415b07 100644 --- a/test/e2e/nstemplatetier_test.go +++ b/test/e2e/nstemplatetier_test.go @@ -11,6 +11,7 @@ import ( testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" diff --git a/test/e2e/parallel/serviceaccount_test.go b/test/e2e/parallel/serviceaccount_test.go index 9bec4f295..e5aa9b7cb 100644 --- a/test/e2e/parallel/serviceaccount_test.go +++ b/test/e2e/parallel/serviceaccount_test.go @@ -8,6 +8,7 @@ import ( "github.com/codeready-toolchain/api/api/v1alpha1" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/assert" diff --git a/test/e2e/parallel/space_cleanup_test.go b/test/e2e/parallel/space_cleanup_test.go index a1f7c6d4b..c0b6d9350 100644 --- a/test/e2e/parallel/space_cleanup_test.go +++ b/test/e2e/parallel/space_cleanup_test.go @@ -9,6 +9,8 @@ import ( "github.com/codeready-toolchain/toolchain-common/pkg/states" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" + testsupportsb "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "k8s.io/apimachinery/pkg/types" @@ -208,7 +210,7 @@ func setupForSpaceBindingCleanupTest(t *testing.T, awaitilities wait.Awaitilitie EnsureMUR(). RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin())...). Execute(t).Resources() - spaceBinding := CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") + spaceBinding := testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") appstudioTier, err := awaitilities.Host().WaitForNSTemplateTier(t, "appstudio") require.NoError(t, err) // make sure that the NSTemplateSet associated with the Space was updated after the space binding was created (new entry in the `spec.SpaceRoles`) diff --git a/test/e2e/parallel/space_test.go b/test/e2e/parallel/space_test.go index c7283b628..39a9f05c4 100644 --- a/test/e2e/parallel/space_test.go +++ b/test/e2e/parallel/space_test.go @@ -8,6 +8,8 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" + testsupportsb "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" @@ -169,7 +171,7 @@ func TestSpaceRoles(t *testing.T) { Resources() // when the `spaceguest` user is bound to the space as an admin - guestBinding := CreateSpaceBinding(t, hostAwait, guestMUR, s, "admin") + guestBinding := testsupportsb.CreateSpaceBinding(t, hostAwait, guestMUR, s, "admin") // then require.NoError(t, err) @@ -432,7 +434,7 @@ func TestSubSpaces(t *testing.T) { // when // we create spaceBinding for subSpace // override the parentMUR and give him admin role (was maintainer previously) - CreateSpaceBinding(t, awaitilities.Host(), parentMUR, subSpace, "admin") + testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), parentMUR, subSpace, "admin") // then // subSpace should have usernames and roles from parentSpaceBindings+subSpaceBindings diff --git a/test/e2e/parallel/spacebindingrequest_test.go b/test/e2e/parallel/spacebindingrequest_test.go index 4d02fc893..87e587d1c 100644 --- a/test/e2e/parallel/spacebindingrequest_test.go +++ b/test/e2e/parallel/spacebindingrequest_test.go @@ -14,6 +14,8 @@ import ( testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + testsupportspace "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/types" @@ -97,7 +99,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { t.Run("error", func(t *testing.T) { t.Run("unable create space binding request with invalid SpaceRole", func(t *testing.T) { - space, _, _ := CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) + space, _, _ := testsupportspace.CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) // wait for the namespace to be provisioned since we will be creating the SpaceBindingRequest into it. space, err := hostAwait.WaitForSpace(t, space.Name, UntilSpaceHasAnyProvisionedNamespaces()) require.NoError(t, err) @@ -115,7 +117,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { spaceBindingRequest := CreateSpaceBindingRequest(t, awaitilities, memberAwait.ClusterName, WithSpecSpaceRole("invalid"), // set invalid spacerole WithSpecMasterUserRecord(mur.GetName()), - WithNamespace(GetDefaultNamespace(space.Status.ProvisionedNamespaces)), + WithNamespace(testsupportspace.GetDefaultNamespace(space.Status.ProvisionedNamespaces)), ) // then @@ -131,7 +133,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { }) t.Run("unable create space binding request with invalid MasterUserRecord", func(t *testing.T) { - space, _, _ := CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) + space, _, _ := testsupportspace.CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) // wait for the namespace to be provisioned since we will be creating the SpaceBindingRequest into it. space, err := hostAwait.WaitForSpace(t, space.Name, UntilSpaceHasAnyProvisionedNamespaces()) require.NoError(t, err) @@ -139,7 +141,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { spaceBindingRequest := CreateSpaceBindingRequest(t, awaitilities, memberAwait.ClusterName, WithSpecSpaceRole("admin"), WithSpecMasterUserRecord("invalidMUR"), // we set an invalid MUR - WithNamespace(GetDefaultNamespace(space.Status.ProvisionedNamespaces)), + WithNamespace(testsupportspace.GetDefaultNamespace(space.Status.ProvisionedNamespaces)), ) // then @@ -231,7 +233,7 @@ func TestUpdateSpaceBindingRequest(t *testing.T) { } func NewSpaceBindingRequest(t *testing.T, awaitilities Awaitilities, memberAwait *MemberAwaitility, hostAwait *HostAwaitility, spaceRole string) (*toolchainv1alpha1.Space, *toolchainv1alpha1.SpaceBindingRequest, *toolchainv1alpha1.SpaceBinding) { - space, firstUserSignup, _ := CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) + space, firstUserSignup, _ := testsupportspace.CreateSpace(t, awaitilities, testspace.WithTierName("appstudio"), testspace.WithSpecTargetCluster(memberAwait.ClusterName)) // wait for the namespace to be provisioned since we will be creating the SpaceBindingRequest into it. space, err := hostAwait.WaitForSpace(t, space.Name, UntilSpaceHasAnyProvisionedNamespaces()) require.NoError(t, err) @@ -249,7 +251,7 @@ func NewSpaceBindingRequest(t *testing.T, awaitilities Awaitilities, memberAwait spaceBindingRequest := CreateSpaceBindingRequest(t, awaitilities, memberAwait.ClusterName, WithSpecSpaceRole(spaceRole), WithSpecMasterUserRecord(secondUserMUR.GetName()), - WithNamespace(GetDefaultNamespace(space.Status.ProvisionedNamespaces)), + WithNamespace(testsupportspace.GetDefaultNamespace(space.Status.ProvisionedNamespaces)), ) // then @@ -283,6 +285,6 @@ func NewSpaceBindingRequest(t *testing.T, awaitilities Awaitilities, memberAwait SpaceRole(tier.Spec.SpaceRoles[spaceRole].TemplateRef, secondUserMUR.Name))) require.NoError(t, err) } - VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name) + testsupportspace.VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name) return space, spaceBindingRequest, spaceBinding } diff --git a/test/e2e/parallel/spacerequest_test.go b/test/e2e/parallel/spacerequest_test.go index d6039a405..ad80daddc 100644 --- a/test/e2e/parallel/spacerequest_test.go +++ b/test/e2e/parallel/spacerequest_test.go @@ -7,6 +7,7 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/cluster" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/types" diff --git a/test/e2e/proxy_test.go b/test/e2e/proxy_test.go index b258a9f51..db1e7130c 100644 --- a/test/e2e/proxy_test.go +++ b/test/e2e/proxy_test.go @@ -23,6 +23,7 @@ import ( testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" appstudiov1 "github.com/codeready-toolchain/toolchain-e2e/testsupport/appstudio/api/v1alpha1" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/test/e2e/space_autocompletion_test.go b/test/e2e/space_autocompletion_test.go index 37db2017e..31ea9be33 100644 --- a/test/e2e/space_autocompletion_test.go +++ b/test/e2e/space_autocompletion_test.go @@ -9,6 +9,7 @@ import ( testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/assert" diff --git a/test/migration/setup_runner.go b/test/migration/setup_runner.go index a9c9f8ffc..0a759ae02 100644 --- a/test/migration/setup_runner.go +++ b/test/migration/setup_runner.go @@ -11,6 +11,7 @@ import ( testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport" "github.com/codeready-toolchain/toolchain-e2e/testsupport/cleanup" + tsspace "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" @@ -70,7 +71,7 @@ func (r *SetupMigrationRunner) createAndWaitForSpace(t *testing.T, name, tierNam err := hostAwait.Client.Create(context.TODO(), space) require.NoError(t, err) - _, _, binding := testsupport.CreateMurWithAdminSpaceBindingForSpace(t, r.Awaitilities, space, r.WithCleanup) + _, _, binding := tsspace.CreateMurWithAdminSpaceBindingForSpace(t, r.Awaitilities, space, r.WithCleanup) tier, err := hostAwait.WaitForNSTemplateTier(t, tierName) require.NoError(t, err) diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index d1de7076c..27b5ce872 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -13,6 +13,7 @@ import ( "github.com/codeready-toolchain/toolchain-e2e/test/migration" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" "github.com/codeready-toolchain/toolchain-e2e/testsupport/cleanup" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/require" diff --git a/testsupport/socialevent.go b/testsupport/socialevent.go deleted file mode 100644 index 6be762bd5..000000000 --- a/testsupport/socialevent.go +++ /dev/null @@ -1,30 +0,0 @@ -package testsupport - -import ( - "time" - - toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// NewSocialEvent returns a new SocialEvent with the given name and tiername, -// starting: now -// ending: 1hr later -// max attendees: 10 -func NewSocialEvent(namespace, name, userTier, spaceTier string) *toolchainv1alpha1.SocialEvent { - se := &toolchainv1alpha1.SocialEvent{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: name, - }, - Spec: toolchainv1alpha1.SocialEventSpec{ - UserTier: userTier, - SpaceTier: spaceTier, - StartTime: metav1.Now(), - EndTime: metav1.NewTime(time.Now().Add(1 * time.Hour)), - MaxAttendees: 10, - }, - } - return se -} diff --git a/testsupport/space.go b/testsupport/space/space.go similarity index 92% rename from testsupport/space.go rename to testsupport/space/space.go index 1f37e1ab6..ba3f4d09f 100644 --- a/testsupport/space.go +++ b/testsupport/space/space.go @@ -1,4 +1,4 @@ -package testsupport +package space import ( "fmt" @@ -8,7 +8,10 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" testtier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier" + "github.com/codeready-toolchain/toolchain-e2e/testsupport" + testsupportsb "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" + "github.com/codeready-toolchain/toolchain-e2e/testsupport/util" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/gofrs/uuid" @@ -21,7 +24,7 @@ import ( func CreateSpace(t *testing.T, awaitilities wait.Awaitilities, opts ...testspace.Option) (*toolchainv1alpha1.Space, *toolchainv1alpha1.UserSignup, *toolchainv1alpha1.SpaceBinding) { // we need to create a MUR & SpaceBinding, otherwise, the Space could be automatically deleted by the SpaceCleanup controller username := uuid.Must(uuid.NewV4()).String() - signup, mur := NewSignupRequest(awaitilities). + signup, mur := testsupport.NewSignupRequest(awaitilities). Username(username). Email(username + "@acme.com"). ManuallyApprove(). @@ -31,7 +34,7 @@ func CreateSpace(t *testing.T, awaitilities wait.Awaitilities, opts ...testspace t.Logf("The UserSignup %s and MUR %s were created", signup.Name, mur.Name) // create the actual space - space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, NewObjectNamePrefix(t), opts...) + space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, util.NewObjectNamePrefix(t), opts...) space, _, err := awaitilities.Host().CreateSpaceAndSpaceBinding(t, mur, space, "admin") require.NoError(t, err) space, err = awaitilities.Host().WaitForSpace(t, space.Name, @@ -63,20 +66,20 @@ func CreateSpace(t *testing.T, awaitilities wait.Awaitilities, opts ...testspace // CreateSpaceWithBinding initializes a new Space object using the NewSpace function, and then creates it in the cluster // It also automatically creates SpaceBinding for it and for the given MasterUserRecord func CreateSpaceWithBinding(t *testing.T, awaitilities wait.Awaitilities, mur *toolchainv1alpha1.MasterUserRecord, opts ...testspace.Option) (*toolchainv1alpha1.Space, *toolchainv1alpha1.SpaceBinding) { - space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, NewObjectNamePrefix(t), opts...) + space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, util.NewObjectNamePrefix(t), opts...) err := awaitilities.Host().CreateWithCleanup(t, space) require.NoError(t, err) // we need to create the SpaceBinding, otherwise, the Space could be automatically deleted by the SpaceCleanup controller - spaceBinding := CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") + spaceBinding := testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") return space, spaceBinding } // CreateSubSpace initializes a new Space object using the NewSpace function, and sets the parentSpace field value accordingly. func CreateSubSpace(t *testing.T, awaitilities wait.Awaitilities, opts ...testspace.Option) *toolchainv1alpha1.Space { - space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, NewObjectNamePrefix(t), opts...) + space := testspace.NewSpaceWithGeneratedName(awaitilities.Host().Namespace, util.NewObjectNamePrefix(t), opts...) err := awaitilities.Host().CreateWithCleanup(t, space) require.NoError(t, err) @@ -164,7 +167,7 @@ func verifyResourcesProvisionedForSpace(t *testing.T, hostAwait *wait.HostAwaiti func CreateMurWithAdminSpaceBindingForSpace(t *testing.T, awaitilities wait.Awaitilities, space *toolchainv1alpha1.Space, cleanup bool) (*toolchainv1alpha1.UserSignup, *toolchainv1alpha1.MasterUserRecord, *toolchainv1alpha1.SpaceBinding) { username := space.Name - builder := NewSignupRequest(awaitilities). + builder := testsupport.NewSignupRequest(awaitilities). Username(username). Email(username + "@acme.com"). ManuallyApprove(). @@ -178,9 +181,9 @@ func CreateMurWithAdminSpaceBindingForSpace(t *testing.T, awaitilities wait.Awai t.Logf("The UserSignup %s and MUR %s were created", signup.Name, mur.Name) var binding *toolchainv1alpha1.SpaceBinding if cleanup { - binding = CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") + binding = testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") } else { - binding = CreateSpaceBindingWithoutCleanup(t, awaitilities.Host(), mur, space, "admin") + binding = testsupportsb.CreateSpaceBindingWithoutCleanup(t, awaitilities.Host(), mur, space, "admin") } t.Logf("The SpaceBinding %s was created", binding.Name) return signup, mur, binding diff --git a/testsupport/spacerequest.go b/testsupport/space/spacerequest.go similarity index 93% rename from testsupport/spacerequest.go rename to testsupport/space/spacerequest.go index f4a893fc2..ee3e311c1 100644 --- a/testsupport/spacerequest.go +++ b/testsupport/space/spacerequest.go @@ -1,4 +1,4 @@ -package testsupport +package space import ( "context" @@ -6,6 +6,7 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" + "github.com/codeready-toolchain/toolchain-e2e/testsupport/util" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/assert" @@ -20,7 +21,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -type SpaceRequestOption func(request *toolchainv1alpha1.SpaceRequest) +type SpaceRequestOption func(request *toolchainv1alpha1.SpaceRequest) // nolint:revive func WithSpecTargetClusterRoles(clusterRoles []string) SpaceRequestOption { return func(s *toolchainv1alpha1.SpaceRequest) { @@ -34,7 +35,7 @@ func WithSpecTierName(tierName string) SpaceRequestOption { } } -func InNamespace(namespace string) SpaceRequestOption { +func WithNamespace(namespace string) SpaceRequestOption { return func(s *toolchainv1alpha1.SpaceRequest) { s.ObjectMeta.Namespace = namespace } @@ -50,7 +51,7 @@ func CreateSpaceRequest(t *testing.T, awaitilities wait.Awaitilities, memberName require.NoError(t, err) // create the space request in the "default" namespace provisioned by the parentSpace - spaceRequest := NewSpaceRequest(t, append(opts, InNamespace(GetDefaultNamespace(parentSpace.Status.ProvisionedNamespaces)))...) + spaceRequest := NewSpaceRequest(t, append(opts, WithNamespace(GetDefaultNamespace(parentSpace.Status.ProvisionedNamespaces)))...) require.NotEmpty(t, spaceRequest) err = memberAwait.CreateWithCleanup(t, spaceRequest) require.NoError(t, err) @@ -61,7 +62,7 @@ func CreateSpaceRequest(t *testing.T, awaitilities wait.Awaitilities, memberName // NewSpaceRequest initializes a new SpaceRequest object with the given options. // By default sets appstudio tier and tenant roles for the cluster to use func NewSpaceRequest(t *testing.T, opts ...SpaceRequestOption) *toolchainv1alpha1.SpaceRequest { - namePrefix := NewObjectNamePrefix(t) + namePrefix := util.NewObjectNamePrefix(t) spaceRequest := &toolchainv1alpha1.SpaceRequest{ ObjectMeta: metav1.ObjectMeta{ diff --git a/testsupport/spacebinding.go b/testsupport/spacebinding/spacebinding.go similarity index 99% rename from testsupport/spacebinding.go rename to testsupport/spacebinding/spacebinding.go index ea403fc77..856c36d88 100644 --- a/testsupport/spacebinding.go +++ b/testsupport/spacebinding/spacebinding.go @@ -1,4 +1,4 @@ -package testsupport +package spacebinding import ( "context" diff --git a/testsupport/spacebindingrequest.go b/testsupport/spacebinding/spacebindingrequest.go similarity index 89% rename from testsupport/spacebindingrequest.go rename to testsupport/spacebinding/spacebindingrequest.go index 45065aaa9..f18793b8d 100644 --- a/testsupport/spacebindingrequest.go +++ b/testsupport/spacebinding/spacebindingrequest.go @@ -1,16 +1,17 @@ -package testsupport +package spacebinding import ( "testing" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" + "github.com/codeready-toolchain/toolchain-e2e/testsupport/util" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type SpaceBindingRequestOption func(request *toolchainv1alpha1.SpaceBindingRequest) +type SpaceBindingRequestOption func(request *toolchainv1alpha1.SpaceBindingRequest) //nolint:revive func WithSpecSpaceRole(spaceRole string) SpaceBindingRequestOption { return func(s *toolchainv1alpha1.SpaceBindingRequest) { @@ -33,7 +34,7 @@ func WithNamespace(ns string) SpaceBindingRequestOption { func CreateSpaceBindingRequest(t *testing.T, awaitilities wait.Awaitilities, memberName string, opts ...SpaceBindingRequestOption) *toolchainv1alpha1.SpaceBindingRequest { memberAwait, err := awaitilities.Member(memberName) require.NoError(t, err) - namePrefix := NewObjectNamePrefix(t) + namePrefix := util.NewObjectNamePrefix(t) spaceBindingRequest := &toolchainv1alpha1.SpaceBindingRequest{ ObjectMeta: metav1.ObjectMeta{ diff --git a/testsupport/tier_template.go b/testsupport/tier_template.go deleted file mode 100644 index 9d01eaa8b..000000000 --- a/testsupport/tier_template.go +++ /dev/null @@ -1,29 +0,0 @@ -package testsupport - -import ( - "testing" - - toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" - "github.com/codeready-toolchain/toolchain-e2e/setup/templates" - - "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func NewTierTemplate(t *testing.T, namespace, name, tierName, typeName, revision string, template []byte) *toolchainv1alpha1.TierTemplate { - tierTmpl := &toolchainv1alpha1.TierTemplate{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: name, - }, - Spec: toolchainv1alpha1.TierTemplateSpec{ - TierName: tierName, - Type: typeName, - Revision: revision, - }, - } - tmpl, err := templates.GetTemplateFromContent(template) - require.NoError(t, err) - tierTmpl.Spec.Template = *tmpl - return tierTmpl -} diff --git a/testsupport/user_assertions.go b/testsupport/user_assertions.go index 71d2c8916..5dbb3c220 100644 --- a/testsupport/user_assertions.go +++ b/testsupport/user_assertions.go @@ -6,6 +6,7 @@ import ( "testing" "time" + testsupportsb "github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding" corev1 "k8s.io/api/core/v1" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" @@ -202,7 +203,7 @@ func VerifySpaceRelatedResources(t *testing.T, awaitilities wait.Awaitilities, u wait.UntilSpaceHasStatusTargetCluster(mur.Spec.UserAccounts[0].TargetCluster)) require.NoError(t, err) - VerifySpaceBinding(t, hostAwait, mur.Name, space.Name, "admin") + testsupportsb.VerifySpaceBinding(t, hostAwait, mur.Name, space.Name, "admin") bindings, err := hostAwait.ListSpaceBindings(space.Name) require.NoError(t, err) diff --git a/testsupport/util.go b/testsupport/util/namingutil.go similarity index 72% rename from testsupport/util.go rename to testsupport/util/namingutil.go index 024e6d1b8..0ea704678 100644 --- a/testsupport/util.go +++ b/testsupport/util/namingutil.go @@ -1,19 +1,11 @@ -package testsupport +package util import ( - "fmt" "regexp" "strings" "testing" - - "github.com/gofrs/uuid" ) -// GenerateName appends generated UUID to the given string -func GenerateName(prefix string) string { - return fmt.Sprintf("%s-%s", prefix, uuid.Must(uuid.NewV4()).String()) -} - var notAllowedChars = regexp.MustCompile("[^-a-z0-9]") // NewObjectNamePrefix creates a namePrefix to be used as .ObjectMeta.GenerateName field.