From d1270544e12d76fc16f356ccf3c9cc8a0a6ff0b5 Mon Sep 17 00:00:00 2001 From: Rafaela Soares Date: Thu, 21 Mar 2024 16:20:03 +0000 Subject: [PATCH] cleanup packages being imported more than once --- .../masteruserrecord_controller_test.go | 31 +-- controllers/masteruserrecord/sync_test.go | 3 +- .../notification_controller_test.go | 5 +- .../space_spacerequest_mapper_test.go | 3 +- .../spacerequest_controller_test.go | 261 +++++++++--------- .../toolchainconfig_controller_test.go | 3 +- pkg/space/space_test.go | 10 +- test/counter.go | 3 +- test/spacebinding/spacebinding.go | 13 +- 9 files changed, 161 insertions(+), 171 deletions(-) diff --git a/controllers/masteruserrecord/masteruserrecord_controller_test.go b/controllers/masteruserrecord/masteruserrecord_controller_test.go index cc7ec718a..48fd5bad4 100644 --- a/controllers/masteruserrecord/masteruserrecord_controller_test.go +++ b/controllers/masteruserrecord/masteruserrecord_controller_test.go @@ -31,7 +31,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -40,7 +39,7 @@ var testLog = ctrl.Log.WithName("test") func TestAddFinalizer(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) signup := commonsignup.NewUserSignup(commonsignup.WithName("john-123")) mur := murtest.NewMasterUserRecord(t, "john", murtest.WithOwnerLabel("john-123")) @@ -197,7 +196,7 @@ func TestAddFinalizer(t *testing.T) { func TestCreateUserAccountSuccessful(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.WithOwnerLabel("john-123")) @@ -249,7 +248,7 @@ func TestCreateUserAccountSuccessful(t *testing.T) { func TestUserAccountSynchronizeSuccessfulWhenPropagatedClaimsModified(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) signup := commonsignup.NewUserSignup(commonsignup.WithName("ricky-123")) @@ -332,7 +331,7 @@ func TestUserAccountSynchronizeSuccessfulWhenPropagatedClaimsModified(t *testing func TestCreateUserAccountWhenItWasPreviouslyDeleted(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.WithOwnerLabel("john-123"), @@ -380,7 +379,7 @@ func TestCreateUserAccountWhenItWasPreviouslyDeleted(t *testing.T) { func TestWithMultipleMembersAndSpaces(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) signup := commonsignup.NewUserSignup(commonsignup.WithName("john-123")) @@ -626,7 +625,7 @@ func TestWithMultipleMembersAndSpaces(t *testing.T) { func TestRequeueWhenUserAccountDeleted(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.AdditionalAccounts(commontest.Member2ClusterName), murtest.Finalizer("finalizer.toolchain.dev.openshift.com")) userAccount1 := uatest.NewUserAccountFromMur(mur) @@ -673,7 +672,7 @@ func TestRequeueWhenUserAccountDeleted(t *testing.T) { func TestCreateSynchronizeOrDeleteUserAccountFailed(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.Finalizer("finalizer.toolchain.dev.openshift.com"), @@ -974,7 +973,7 @@ func TestCreateSynchronizeOrDeleteUserAccountFailed(t *testing.T) { // todo change test to support updates of multiple UserAccounts func TestModifyUserAccount(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.WithOwnerLabel("john-123"), @@ -1033,7 +1032,7 @@ func TestModifyUserAccount(t *testing.T) { } func TestSyncMurStatusWithUserAccountStatuses(t *testing.T) { - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) spaceBinding := spacebindingtest.NewSpaceBinding("john", "john-space", "admin", "john-123") space := spacetest.NewSpace(commontest.HostOperatorNs, "john-space", @@ -1193,7 +1192,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { t.Run("success", func(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.ToBeDeleted()) @@ -1233,7 +1232,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { t.Run("test wait for UserAccount deletion in progress before removing MUR finalizer", func(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john-wait-for-ua", murtest.ToBeDeleted()) @@ -1277,7 +1276,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { t.Run("test wait for UserAccount deletion takes too long", func(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) // A basic userSignup to set as the mur owner @@ -1313,7 +1312,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { t.Run("test UserAccount deletion has foreground propagation policy", func(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john-wait-for-ua", murtest.ToBeDeleted()) @@ -1345,7 +1344,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { func TestDeleteMultipleUserAccountsViaMasterUserRecordBeingDeleted(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.Finalizer("finalizer.toolchain.dev.openshift.com"), @@ -1400,7 +1399,7 @@ func TestDeleteMultipleUserAccountsViaMasterUserRecordBeingDeleted(t *testing.T) func TestDisablingMasterUserRecord(t *testing.T) { // given - logf.SetLogger(zap.New(zap.UseDevMode(true))) + log.SetLogger(zap.New(zap.UseDevMode(true))) s := apiScheme(t) mur := murtest.NewMasterUserRecord(t, "john", murtest.WithOwnerLabel("john-123"), diff --git a/controllers/masteruserrecord/sync_test.go b/controllers/masteruserrecord/sync_test.go index 3e8162226..806e36bd3 100644 --- a/controllers/masteruserrecord/sync_test.go +++ b/controllers/masteruserrecord/sync_test.go @@ -23,7 +23,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -840,7 +839,7 @@ func TestRemoveAccountFromStatus(t *testing.T) { func TestRoutes(t *testing.T) { // given l := zap.New(zap.UseDevMode(true)) - logf.SetLogger(l) + log.SetLogger(l) apiScheme(t) masterUserRec := murtest.NewMasterUserRecord(t, "john", diff --git a/controllers/notification/notification_controller_test.go b/controllers/notification/notification_controller_test.go index e439b8731..2435bb9b8 100644 --- a/controllers/notification/notification_controller_test.go +++ b/controllers/notification/notification_controller_test.go @@ -22,7 +22,6 @@ import ( "github.com/spf13/cast" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - apiv1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -353,7 +352,7 @@ func AssertThatNotificationIsDeleted(t *testing.T, cl runtimeclient.Client, name func sentCond() toolchainv1alpha1.Condition { return toolchainv1alpha1.Condition{ Type: toolchainv1alpha1.NotificationSent, - Status: apiv1.ConditionTrue, + Status: corev1.ConditionTrue, Reason: "Sent", LastTransitionTime: metav1.Time{Time: time.Now()}, } @@ -371,7 +370,7 @@ func deliveryErrorCond(msg string) toolchainv1alpha1.Condition { func deletionCond(msg string) toolchainv1alpha1.Condition { return toolchainv1alpha1.Condition{ Type: toolchainv1alpha1.NotificationDeletionError, - Status: apiv1.ConditionTrue, + Status: corev1.ConditionTrue, Reason: toolchainv1alpha1.NotificationDeletionErrorReason, Message: msg, LastTransitionTime: metav1.Time{Time: time.Now()}, diff --git a/controllers/spacerequest/space_spacerequest_mapper_test.go b/controllers/spacerequest/space_spacerequest_mapper_test.go index 9ca715acd..de15ff0a3 100644 --- a/controllers/spacerequest/space_spacerequest_mapper_test.go +++ b/controllers/spacerequest/space_spacerequest_mapper_test.go @@ -7,7 +7,6 @@ import ( "github.com/codeready-toolchain/host-operator/controllers/spacerequest" spacerequesttest "github.com/codeready-toolchain/host-operator/test/spacerequest" "github.com/codeready-toolchain/toolchain-common/pkg/test" - "github.com/codeready-toolchain/toolchain-common/pkg/test/space" spacetest "github.com/codeready-toolchain/toolchain-common/pkg/test/space" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -19,7 +18,7 @@ func TestMapToSpaceRequestByLabel(t *testing.T) { // given spaceRequest := spacerequesttest.NewSpaceRequest("mySpaceRequest", "jane") // following space has a spaceRequest associated - subSpace := spacetest.NewSpace(test.HostOperatorNs, "subSpace", space.WithLabel(v1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), space.WithLabel(v1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace())) + subSpace := spacetest.NewSpace(test.HostOperatorNs, "subSpace", spacetest.WithLabel(v1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), spacetest.WithLabel(v1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace())) // following space has no spaceRequest associated spacenosr := spacetest.NewSpace(test.HostOperatorNs, "nospacerequest") diff --git a/controllers/spacerequest/spacerequest_controller_test.go b/controllers/spacerequest/spacerequest_controller_test.go index c59d83585..39afc87e2 100644 --- a/controllers/spacerequest/spacerequest_controller_test.go +++ b/controllers/spacerequest/spacerequest_controller_test.go @@ -14,7 +14,6 @@ import ( tiertest "github.com/codeready-toolchain/host-operator/test/nstemplatetier" spacerequesttest "github.com/codeready-toolchain/host-operator/test/spacerequest" commoncluster "github.com/codeready-toolchain/toolchain-common/pkg/cluster" - "github.com/codeready-toolchain/toolchain-common/pkg/test" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" spacetest "github.com/codeready-toolchain/toolchain-common/pkg/test/space" @@ -38,7 +37,7 @@ func TestCreateSpaceRequest(t *testing.T) { appstudioEnvTier := tiertest.AppStudioEnvTier(t, tiertest.AppStudioEnvTemplates) srNamespace := spacerequesttest.NewNamespace("jane") srClusterRoles := []string{commoncluster.RoleLabel(commoncluster.Tenant)} - parentSpace := spacetest.NewSpace(test.HostOperatorNs, "jane") + parentSpace := spacetest.NewSpace(commontest.HostOperatorNs, "jane") t.Run("success", func(t *testing.T) { sr := spacerequesttest.NewSpaceRequest("jane", srNamespace.GetName(), spacerequesttest.WithTierName("appstudio-env"), @@ -47,8 +46,8 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("subSpace doesn't exists it should be created", func(t *testing.T) { // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -77,8 +76,8 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithDisableInheritance(true)) // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -102,8 +101,8 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("subSpace exists but is not ready yet", func(t *testing.T) { // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - subSpace := spacetest.NewSpace(test.HostOperatorNs, "jane-subs", + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, "jane-subs", spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -112,7 +111,7 @@ func TestCreateSpaceRequest(t *testing.T) { spacetest.WithStatusTargetCluster(member1.Name), spacetest.WithSpecTargetClusterRoles(srClusterRoles), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -126,7 +125,7 @@ func TestCreateSpaceRequest(t *testing.T) { HasConditions(spacetest.Provisioning()). // condition is reflected from space status HasFinalizer() // a subspace is created with the tierName and cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, "jane-subs", hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, "jane-subs", hostClient). HasSpecTargetClusterRoles(srClusterRoles). HasConditions(spacetest.Provisioning()). HasTier(sr.Spec.TierName). @@ -135,12 +134,12 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("subSpace is provisioned", func(t *testing.T) { // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, Namespace: "jane-env", }) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -153,7 +152,7 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -169,7 +168,7 @@ func TestCreateSpaceRequest(t *testing.T) { HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env", SecretRef: "jane-abc"}}). // has access details for the provisioned namespace, the secret name may not match exactly since it is generated the first time it's created HasFinalizer() // a subspace is created with the tierName and cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). HasSpecTargetClusterRoles(srClusterRoles). HasConditions(spacetest.Ready()). HasTier(sr.Spec.TierName). @@ -179,7 +178,7 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("subSpace has multiple provisioned namespaces", func(t *testing.T) { // given // the default namespace has already an access secret provisioned - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, Namespace: "jane-env1", @@ -190,7 +189,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, ) // this space has multiple namespaces provisioned - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -209,7 +208,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, }), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -225,7 +224,7 @@ func TestCreateSpaceRequest(t *testing.T) { HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "existingDevSecret"}, {Name: "jane-env2", SecretRef: "existingDevSecret2"}}). // expected secrets are there. The secret names may not match exactly since it is generated the first time it's created HasFinalizer() // a subspace is created with the tierName and cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). HasSpecTargetClusterRoles(srClusterRoles). HasConditions(spacetest.Ready()). HasTier(sr.Spec.TierName). @@ -234,9 +233,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("spacerequest created on member2", func(t *testing.T) { // when - member1 := NewMemberClusterWithClient(test.NewFakeClient(t), "member-1", corev1.ConditionTrue) - member2 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-2", corev1.ConditionTrue) // space request and namespace are on member2 - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t), "member-1", corev1.ConditionTrue) + member2 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-2", corev1.ConditionTrue) // space request and namespace are on member2 + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1, member2) _, err := ctrl.Reconcile(context.TODO(), requestFor(sr)) @@ -255,12 +254,12 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("spacerequest has empty target cluster roles", func(t *testing.T) { // when - parentSpaceWithTarget := spacetest.NewSpace(test.HostOperatorNs, "jane", spacetest.WithSpecTargetCluster("member-2")) + parentSpaceWithTarget := spacetest.NewSpace(commontest.HostOperatorNs, "jane", spacetest.WithSpecTargetCluster("member-2")) spaceRequest := spacerequesttest.NewSpaceRequest("noroles", srNamespace.GetName(), spacerequesttest.WithTierName("appstudio-env")) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t), "member-1", corev1.ConditionTrue) - member2 := NewMemberClusterWithClient(test.NewFakeClient(t, spaceRequest, srNamespace), "member-2", corev1.ConditionTrue) // space request and namespace are on member2 - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpaceWithTarget) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t), "member-1", corev1.ConditionTrue) + member2 := NewMemberClusterWithClient(commontest.NewFakeClient(t, spaceRequest, srNamespace), "member-2", corev1.ConditionTrue) // space request and namespace are on member2 + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpaceWithTarget) ctrl := newReconciler(t, hostClient, member1, member2) _, err := ctrl.Reconcile(context.TODO(), requestFor(spaceRequest)) @@ -280,14 +279,14 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("subSpace target cluster is different from spacerequest cluster", func(t *testing.T) { // given - parentSpaceWithTarget := spacetest.NewSpace(test.HostOperatorNs, "jane", spacetest.WithSpecTargetCluster("member-1")) + parentSpaceWithTarget := spacetest.NewSpace(commontest.HostOperatorNs, "jane", spacetest.WithSpecTargetCluster("member-1")) spaceRequest := spacerequesttest.NewSpaceRequest("jane", "jane-tenant", spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithTargetClusterRoles([]string{"member-2"})) // the provisioned namespace is targeted for member-2 spaceRequestNamespace := spacerequesttest.NewNamespace("jane") - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, spaceRequest, spaceRequestNamespace), "member-1", corev1.ConditionTrue) // spacerequest is created on member-1 but has target cluster member-2 + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, spaceRequest, spaceRequestNamespace), "member-1", corev1.ConditionTrue) // spacerequest is created on member-1 but has target cluster member-2 // the provisioned namespace is on different cluster then the spacerequest resource - member2 := NewMemberClusterWithClient(test.NewFakeClient(t), "member-2", corev1.ConditionTrue, + member2 := NewMemberClusterWithClient(commontest.NewFakeClient(t), "member-2", corev1.ConditionTrue, WithClusterRoleLabel(commoncluster.RoleLabel("member-2")), ) commontest.SetupGockForServiceAccounts(t, member2.APIEndpoint, types.NamespacedName{ @@ -295,7 +294,7 @@ func TestCreateSpaceRequest(t *testing.T) { Namespace: "jane-env1", }, ) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpaceWithTarget, spaceRequest), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpaceWithTarget, spaceRequest), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -310,7 +309,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, }), spacetest.WithTierName(spaceRequest.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpaceWithTarget, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpaceWithTarget, subSpace) ctrl := newReconciler(t, hostClient, member1, member2) // when @@ -326,7 +325,7 @@ func TestCreateSpaceRequest(t *testing.T) { HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "jane-xyz1"}}). HasFinalizer() // a subspace is created with the tierName and cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpaceWithTarget, spaceRequest), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpaceWithTarget, spaceRequest), hostClient). HasSpecTargetClusterRoles([]string{"member-2"}). HasConditions(spacetest.Ready()). HasTier(spaceRequest.Spec.TierName). @@ -334,12 +333,12 @@ func TestCreateSpaceRequest(t *testing.T) { }) t.Run("member1 GET request fails, member2 GET returns not found but SpaceRequest is on member3", func(t *testing.T) { - member1Client := test.NewFakeClient(t) + member1Client := commontest.NewFakeClient(t) member1Client.MockGet = mockGetSpaceRequestFail(member1Client) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - member2 := NewMemberClusterWithClient(test.NewFakeClient(t), "member-2", corev1.ConditionTrue) - member3 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-3", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + member2 := NewMemberClusterWithClient(commontest.NewFakeClient(t), "member-2", corev1.ConditionTrue) + member3 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-3", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1, member2, member3) // when @@ -365,7 +364,7 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithStatusNamespaceAccess(toolchainv1alpha1.NamespaceAccess{Name: "jane-env", SecretRef: "jane-xyz1"}), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithSpecTargetClusterRoles(srClusterRoles), @@ -377,13 +376,13 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(sr.Spec.TierName)) - member1Client := test.NewFakeClient(t, spaceRequest, srNamespace) + member1Client := commontest.NewFakeClient(t, spaceRequest, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, Namespace: "jane-env", }) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // check that there are no secret prior to reconcile secrets := &corev1.SecretList{} @@ -419,7 +418,7 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("secret in SpaceRequest status and referenced secret already exist", func(t *testing.T) { // given - kubeconfigSecret1 := test.CreateSecret("jane-xyz1", sr.Namespace, map[string][]byte{ + kubeconfigSecret1 := commontest.CreateSecret("jane-xyz1", sr.Namespace, map[string][]byte{ "kubeconfig": []byte("kubeconfig1"), }) kubeconfigSecret1.StringData = map[string]string{ @@ -435,7 +434,7 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithStatusNamespaceAccess(toolchainv1alpha1.NamespaceAccess{Name: "jane-env", SecretRef: "jane-xyz1"}), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithSpecTargetClusterRoles(srClusterRoles), @@ -447,9 +446,9 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(sr.Spec.TierName)) - member1Client := test.NewFakeClient(t, spaceRequest, srNamespace, kubeconfigSecret1) + member1Client := commontest.NewFakeClient(t, spaceRequest, srNamespace, kubeconfigSecret1) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -504,7 +503,7 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithStatusNamespaceAccess(toolchainv1alpha1.NamespaceAccess{Name: "jane-env", SecretRef: "jane-xyz1"}), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, spaceRequest), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, spaceRequest), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithSpecTargetClusterRoles(srClusterRoles), @@ -516,9 +515,9 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(spaceRequest.Spec.TierName)) - member1Client := test.NewFakeClient(t, spaceRequest, srNamespace) + member1Client := commontest.NewFakeClient(t, spaceRequest, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, @@ -573,7 +572,7 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("spacerequest creates secrets for two namespaces", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, @@ -585,7 +584,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, ) // this space has multiple namespaces provisioned - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -604,7 +603,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, }), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -630,7 +629,7 @@ func TestCreateSpaceRequest(t *testing.T) { require.Len(t, secrets.Items, 1) } // a subspace is created with the tierName and cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). HasSpecTargetClusterRoles(srClusterRoles). HasConditions(spacetest.Ready()). HasTier(sr.Spec.TierName). @@ -642,8 +641,8 @@ func TestCreateSpaceRequest(t *testing.T) { spaceRequest := spacerequesttest.NewSpaceRequest("nosecret", spaceRequestNamespace.GetName(), spacerequesttest.WithTierName("base1ns"), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, spaceRequest, spaceRequestNamespace), "member-1", corev1.ConditionTrue) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, spaceRequest), + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, spaceRequest, spaceRequestNamespace), "member-1", corev1.ConditionTrue) + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, spaceRequest), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, spaceRequest.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, spaceRequest.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, parentSpace.GetName()), @@ -658,7 +657,7 @@ func TestCreateSpaceRequest(t *testing.T) { }, }), spacetest.WithTierName(spaceRequest.Spec.TierName)) // it should be created with "base1ns" tier - hostClient := test.NewFakeClient(t, base1nsTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, base1nsTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -686,12 +685,12 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithTargetClusterRoles(srClusterRoles)) t.Run("subSpace is provisioned", func(t *testing.T) { // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: "another-sa-name", // create SA with different name than expected one Namespace: "jane-env", }) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -704,7 +703,7 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when _, err = ctrl.Reconcile(context.TODO(), requestFor(sr)) @@ -722,8 +721,8 @@ func TestCreateSpaceRequest(t *testing.T) { spacerequesttest.WithTargetClusterRoles(srClusterRoles)) t.Run("unable to find SpaceRequest", func(t *testing.T) { - member1 := NewMemberClusterWithClient(test.NewFakeClient(t), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) ctrl := newReconciler(t, hostClient, member1) // when @@ -735,10 +734,10 @@ func TestCreateSpaceRequest(t *testing.T) { require.NoError(t, err) }) t.Run("unable to get SpaceRequest", func(t *testing.T) { - member1Client := test.NewFakeClient(t) + member1Client := commontest.NewFakeClient(t) member1Client.MockGet = mockGetSpaceRequestFail(member1Client) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) ctrl := newReconciler(t, hostClient, member1) // when @@ -750,10 +749,10 @@ func TestCreateSpaceRequest(t *testing.T) { }) t.Run("error while adding finalizer", func(t *testing.T) { - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1Client.MockUpdate = mockUpdateSpaceRequestFail(member1Client) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -764,7 +763,7 @@ func TestCreateSpaceRequest(t *testing.T) { }) t.Run("error while updating status", func(t *testing.T) { - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1Client.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { if _, ok := obj.(*toolchainv1alpha1.SpaceRequest); ok { return fmt.Errorf("mock error") @@ -772,7 +771,7 @@ func TestCreateSpaceRequest(t *testing.T) { return member1Client.Status().Update(ctx, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -783,9 +782,9 @@ func TestCreateSpaceRequest(t *testing.T) { }) t.Run("unable to get parent space name", func(t *testing.T) { - member1Client := test.NewFakeClient(t, sr) + member1Client := commontest.NewFakeClient(t, sr) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) ctrl := newReconciler(t, hostClient, member1) // when @@ -801,9 +800,9 @@ func TestCreateSpaceRequest(t *testing.T) { sr := spacerequesttest.NewSpaceRequest("jane", srNamespace.GetName(), spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) ctrl := newReconciler(t, hostClient, member1) // when @@ -815,13 +814,13 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("unable to update space since it's being deleted", func(t *testing.T) { // given - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithDeletionTimestamp(), // space is being deleted ... spacetest.WithSpecParentSpace("jane")) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -837,9 +836,9 @@ func TestCreateSpaceRequest(t *testing.T) { srNamespace.GetName(), spacerequesttest.WithTierName("unknown"), // this tier doesn't exist spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -856,9 +855,9 @@ func TestCreateSpaceRequest(t *testing.T) { srNamespace.GetName(), spacerequesttest.WithTierName(""), spacerequesttest.WithTargetClusterRoles(srClusterRoles)) - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -870,9 +869,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("error while getting tier", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) hostClient.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") @@ -890,9 +889,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("error creating subSpace", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) hostClient.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") @@ -910,9 +909,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("error listing spaces", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) hostClient.MockList = func(ctx context.Context, list runtimeclient.ObjectList, opts ...runtimeclient.ListOption) error { if _, ok := list.(*toolchainv1alpha1.SpaceList); ok { return fmt.Errorf("mock error") @@ -930,17 +929,17 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("listing spaces with label selectors returns more than one result", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - subSpace1 := spacetest.NewSpace(test.HostOperatorNs, "foo", + subSpace1 := spacetest.NewSpace(commontest.HostOperatorNs, "foo", spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithSpecParentSpace(parentSpace.GetName())) - subSpace2 := spacetest.NewSpace(test.HostOperatorNs, "bar", + subSpace2 := spacetest.NewSpace(commontest.HostOperatorNs, "bar", spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithSpecParentSpace(parentSpace.GetName())) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace1, subSpace2) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace1, subSpace2) ctrl := newReconciler(t, hostClient, member1) // when @@ -952,12 +951,12 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("parent space is being deleted", func(t *testing.T) { // given - parentSpace := spacetest.NewSpace(test.HostOperatorNs, "jane", + parentSpace := spacetest.NewSpace(commontest.HostOperatorNs, "jane", spacetest.WithCondition(spacetest.Terminating()), spacetest.WithDeletionTimestamp()) // parent space for some reason is being deleted - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -969,9 +968,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("parent space is deleted", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) ctrl := newReconciler(t, hostClient, member1) // when @@ -983,9 +982,9 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("unable to get parent space", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier) hostClient.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") @@ -1003,7 +1002,7 @@ func TestCreateSpaceRequest(t *testing.T) { t.Run("error creating secret for provisioned namespace", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1Client.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { if _, ok := obj.(*corev1.Secret); ok { return fmt.Errorf("mock error") @@ -1015,7 +1014,7 @@ func TestCreateSpaceRequest(t *testing.T) { Name: toolchainv1alpha1.AdminServiceAccountName, Namespace: "jane-env", }) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, "jane"), @@ -1028,7 +1027,7 @@ func TestCreateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName(sr.Spec.TierName)) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1075,7 +1074,7 @@ func TestUpdateSpaceRequest(t *testing.T) { require.NoError(t, err) appstudioEnvTier := tiertest.AppStudioEnvTier(t, tiertest.AppStudioEnvTemplates) srNamespace := spacerequesttest.NewNamespace("jane") - parentSpace := spacetest.NewSpace(test.HostOperatorNs, "jane") + parentSpace := spacetest.NewSpace(commontest.HostOperatorNs, "jane") srClusterRoles := []string{commoncluster.RoleLabel(commoncluster.Tenant)} t.Run("success", func(t *testing.T) { @@ -1087,7 +1086,7 @@ func TestUpdateSpaceRequest(t *testing.T) { spacerequesttest.WithTierName(newTier.Name), // space request uses new tier spacerequesttest.WithTargetClusterRoles(srClusterRoles), spacerequesttest.WithFinalizer()) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, parentSpace.GetName()), @@ -1095,8 +1094,8 @@ func TestUpdateSpaceRequest(t *testing.T) { spacetest.WithSpecParentSpace("jane"), spacetest.WithSpecTargetClusterRoles(srClusterRoles), spacetest.WithTierName("appstudio-env")) // subSpace doesn't have yet the new tier - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, newTier, parentSpace, subSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, newTier, parentSpace, subSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1110,7 +1109,7 @@ func TestUpdateSpaceRequest(t *testing.T) { HasSpecTierName(newTier.Name). // space request still has the new tier HasFinalizer() // the subspace is updated with tierName and cluster roles from the spacerequests - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). HasSpecTargetClusterRoles(srClusterRoles). HasTier(newTier.Name). // now also the subSpace reflects same tier HasParentSpace("jane") @@ -1124,7 +1123,7 @@ func TestUpdateSpaceRequest(t *testing.T) { spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithTargetClusterRoles(updatedSRClusterRoles), // add a new cluster role label to check if it's reflected on the subSpace spacerequesttest.WithFinalizer()) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, parentSpace.GetName()), @@ -1133,8 +1132,8 @@ func TestUpdateSpaceRequest(t *testing.T) { spacetest.WithSpecParentSpace("jane"), spacetest.WithSpecTargetClusterRoles(srClusterRoles), // initially the subSpace has only the tenant cluster role label spacetest.WithTierName("appstudio-env")) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1148,7 +1147,7 @@ func TestUpdateSpaceRequest(t *testing.T) { HasSpecTierName("appstudio-env"). HasFinalizer() // the subspace is updated with the tierName and new cluster roles from the spacerequest - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). HasSpecTargetClusterRoles(updatedSRClusterRoles). // now also subSpace has the updated cluster roles HasTier("appstudio-env"). HasParentSpace("jane") @@ -1164,7 +1163,7 @@ func TestUpdateSpaceRequest(t *testing.T) { SecretRef: "jane-qwerty", // secret doesn't exist and name of the secret will change when it will be created }), spacerequesttest.WithFinalizer()) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, parentSpace.GetName()), @@ -1178,12 +1177,12 @@ func TestUpdateSpaceRequest(t *testing.T) { Type: "default", }}), spacetest.WithTierName("appstudio-env")) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{ Name: toolchainv1alpha1.AdminServiceAccountName, Namespace: "jane-env", }) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1206,16 +1205,16 @@ func TestUpdateSpaceRequest(t *testing.T) { srNamespace.GetName(), spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithFinalizer()) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithSpecTargetCluster("member-1"), spacetest.WithCondition(spacetest.Ready()), spacetest.WithSpecParentSpace("jane"), spacetest.WithTierName("anothertier")) // tier name will have to be updated - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace, subSpace) hostClient.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") @@ -1239,7 +1238,7 @@ func TestUpdateSpaceRequest(t *testing.T) { spacerequesttest.WithTargetClusterRoles(srClusterRoles), spacerequesttest.WithStatusTargetClusterURL(""), // target cluster URL is empty spacerequesttest.WithFinalizer()) - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithStatusTargetCluster("invalid"), // let's force an invalid name in the subSpace @@ -1247,8 +1246,8 @@ func TestUpdateSpaceRequest(t *testing.T) { spacetest.WithSpecParentSpace("jane"), spacetest.WithSpecTargetClusterRoles(srClusterRoles), spacetest.WithTierName("appstudio-env")) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1268,7 +1267,7 @@ func TestDeleteSpaceRequest(t *testing.T) { appstudioEnvTier := tiertest.AppStudioEnvTier(t, tiertest.AppStudioEnvTemplates) srNamespace := spacerequesttest.NewNamespace("jane") srClusterRoles := []string{commoncluster.RoleLabel(commoncluster.Tenant)} - parentSpace := spacetest.NewSpace(test.HostOperatorNs, "jane") + parentSpace := spacetest.NewSpace(commontest.HostOperatorNs, "jane") sr := spacerequesttest.NewSpaceRequest("jane", srNamespace.GetName(), spacerequesttest.WithTierName("appstudio-env"), @@ -1278,7 +1277,7 @@ func TestDeleteSpaceRequest(t *testing.T) { t.Run("success", func(t *testing.T) { t.Run("spaceRequest should be in terminating while subSpace is deleted", func(t *testing.T) { // given - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), // subSpace was created from spaceRequest spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), // subSpace was created from spaceRequest spacetest.WithSpecTargetCluster("member-1"), @@ -1286,8 +1285,8 @@ func TestDeleteSpaceRequest(t *testing.T) { spacetest.WithSpecParentSpace("jane"), spacetest.WithSpecTargetClusterRoles(srClusterRoles), spacetest.WithTierName(sr.Spec.TierName)) - member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + member1 := NewMemberClusterWithClient(commontest.NewFakeClient(t, sr, srNamespace), "member-1", corev1.ConditionTrue) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when _, err = ctrl.Reconcile(context.TODO(), requestFor(sr)) @@ -1300,7 +1299,7 @@ func TestDeleteSpaceRequest(t *testing.T) { HasConditions(spacetest.Terminating()). HasFinalizer() // finalizer is still there until subSpace is gone // subSpace is deleted - spacetest.AssertThatSpace(t, test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). + spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient). DoesNotExist() // subSpace is gone t.Run("spaceRequest is deleted when subSpace is gone", func(t *testing.T) { @@ -1323,9 +1322,9 @@ func TestDeleteSpaceRequest(t *testing.T) { spacerequesttest.WithTierName("appstudio-env"), spacerequesttest.WithTargetClusterRoles(srClusterRoles), spacerequesttest.WithDeletionTimestamp()) // spaceRequest was deleted - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1342,11 +1341,11 @@ func TestDeleteSpaceRequest(t *testing.T) { t.Run("failure", func(t *testing.T) { t.Run("unable to set status terminating", func(t *testing.T) { // given - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithSpecParentSpace("jane")) - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1Client.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { if _, ok := obj.(*toolchainv1alpha1.SpaceRequest); ok { return fmt.Errorf("mock error") @@ -1354,7 +1353,7 @@ func TestDeleteSpaceRequest(t *testing.T) { return member1Client.Client.Update(ctx, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1366,7 +1365,7 @@ func TestDeleteSpaceRequest(t *testing.T) { t.Run("failed to remove finalizer", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1Client.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { if _, ok := obj.(*toolchainv1alpha1.SpaceRequest); ok { return fmt.Errorf("mock error") @@ -1374,7 +1373,7 @@ func TestDeleteSpaceRequest(t *testing.T) { return member1Client.Client.Update(ctx, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) ctrl := newReconciler(t, hostClient, member1) // when @@ -1386,9 +1385,9 @@ func TestDeleteSpaceRequest(t *testing.T) { t.Run("unable to list subspaces", func(t *testing.T) { // given - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, parentSpace) hostClient.MockList = func(ctx context.Context, list runtimeclient.ObjectList, opts ...runtimeclient.ListOption) error { if _, ok := list.(*toolchainv1alpha1.SpaceList); ok { return fmt.Errorf("mock error") @@ -1406,13 +1405,13 @@ func TestDeleteSpaceRequest(t *testing.T) { t.Run("unable to delete subSpace", func(t *testing.T) { // given - subSpace := spacetest.NewSpace(test.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), + subSpace := spacetest.NewSpace(commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithSpecParentSpace("jane")) - member1Client := test.NewFakeClient(t, sr, srNamespace) + member1Client := commontest.NewFakeClient(t, sr, srNamespace) member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) - hostClient := test.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) + hostClient := commontest.NewFakeClient(t, appstudioEnvTier, subSpace, parentSpace) hostClient.MockDelete = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.DeleteOption) error { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") @@ -1445,7 +1444,7 @@ func newReconciler(t *testing.T, hostCl runtimeclient.Client, memberClusters ... Config: &commoncluster.Config{ APIEndpoint: c.APIEndpoint, OperatorNamespace: c.OperatorNamespace, - OwnerClusterName: test.MemberClusterName, + OwnerClusterName: commontest.MemberClusterName, RestConfig: &rest.Config{ Host: c.APIEndpoint, TLSClientConfig: rest.TLSClientConfig{ @@ -1460,7 +1459,7 @@ func newReconciler(t *testing.T, hostCl runtimeclient.Client, memberClusters ... return &spacerequest.Reconciler{ Client: hostCl, Scheme: s, - Namespace: test.HostOperatorNs, + Namespace: commontest.HostOperatorNs, MemberClusters: clusters, } } diff --git a/controllers/toolchainconfig/toolchainconfig_controller_test.go b/controllers/toolchainconfig/toolchainconfig_controller_test.go index 204387bee..62275ebfd 100644 --- a/controllers/toolchainconfig/toolchainconfig_controller_test.go +++ b/controllers/toolchainconfig/toolchainconfig_controller_test.go @@ -24,7 +24,6 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -309,7 +308,7 @@ func TestWrapErrorWithUpdateStatus(t *testing.T) { hostCl := test.NewFakeClient(t, config) members := NewGetMemberClusters(NewMemberClusterWithTenantRole(t, "member1", corev1.ConditionTrue), NewMemberClusterWithTenantRole(t, "member2", corev1.ConditionTrue)) controller := newController(t, hostCl, members) - logger := logf.Log.WithName("test") + logger := log.Log.WithName("test") ctx := log.IntoContext(context.TODO(), logger) t.Run("no error provided", func(t *testing.T) { diff --git a/pkg/space/space_test.go b/pkg/space/space_test.go index d289a3d54..eb0553d4e 100644 --- a/pkg/space/space_test.go +++ b/pkg/space/space_test.go @@ -6,12 +6,10 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" spacerequesttest "github.com/codeready-toolchain/host-operator/test/spacerequest" - "github.com/codeready-toolchain/toolchain-common/pkg/cluster" commoncluster "github.com/codeready-toolchain/toolchain-common/pkg/cluster" "github.com/codeready-toolchain/toolchain-common/pkg/test" - commonsignup "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup" - spacetest "github.com/codeready-toolchain/toolchain-common/pkg/test/space" + commonsignup "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup" "github.com/stretchr/testify/assert" ) @@ -27,7 +25,7 @@ func TestNewSpace(t *testing.T) { expectedSpace := spacetest.NewSpace(test.HostOperatorNs, "johny", spacetest.WithTierName("advanced"), spacetest.WithSpecTargetCluster("member-cluster"), - spacetest.WithSpecTargetClusterRoles([]string{cluster.RoleLabel(cluster.Tenant)}), + spacetest.WithSpecTargetClusterRoles([]string{commoncluster.RoleLabel(commoncluster.Tenant)}), spacetest.WithCreatorLabel(userSignup.Name)) assert.Equal(t, expectedSpace, space) } @@ -47,7 +45,7 @@ func TestNewSubSpace(t *testing.T) { expectedSubSpace := spacetest.NewSpace(test.HostOperatorNs, SubSpaceName(parentSpace, sr), spacetest.WithSpecParentSpace(parentSpace.GetName()), spacetest.WithTierName("appstudio"), - spacetest.WithSpecTargetClusterRoles([]string{cluster.RoleLabel(cluster.Tenant)}), + spacetest.WithSpecTargetClusterRoles([]string{commoncluster.RoleLabel(commoncluster.Tenant)}), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr.GetNamespace()), spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, parentSpace.GetName()), @@ -74,7 +72,7 @@ func TestNewSubSubSpace(t *testing.T) { expectedSubSubSpace := spacetest.NewSpace(test.HostOperatorNs, fmt.Sprintf("%s-%s", parentSpace.Name, sr2.UID[:5]), spacetest.WithSpecParentSpace(subSpace.GetName()), spacetest.WithTierName("appstudio"), - spacetest.WithSpecTargetClusterRoles([]string{cluster.RoleLabel(cluster.Tenant)}), + spacetest.WithSpecTargetClusterRoles([]string{commoncluster.RoleLabel(commoncluster.Tenant)}), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestLabelKey, sr2.GetName()), spacetest.WithLabel(toolchainv1alpha1.SpaceRequestNamespaceLabelKey, sr2.GetNamespace()), spacetest.WithLabel(toolchainv1alpha1.ParentSpaceLabelKey, subSpace.GetName()), diff --git a/test/counter.go b/test/counter.go index 539c295c8..3c2d5b9b5 100644 --- a/test/counter.go +++ b/test/counter.go @@ -11,7 +11,6 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/host-operator/pkg/counter" "github.com/codeready-toolchain/host-operator/pkg/metrics" - "github.com/codeready-toolchain/toolchain-common/pkg/test" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" "github.com/codeready-toolchain/toolchain-common/pkg/test/masteruserrecord" spacetest "github.com/codeready-toolchain/toolchain-common/pkg/test/space" @@ -91,7 +90,7 @@ func CreateMultipleUserSignups(prefix string, number int) []runtime.Object { func CreateMultipleSpaces(prefix string, number int, targetCluster string) []runtime.Object { spaces := make([]runtime.Object, number) for index := range spaces { - spaces[index] = spacetest.NewSpace(test.HostOperatorNs, fmt.Sprintf("%s%d", prefix, index), spacetest.WithSpecTargetCluster(targetCluster)) + spaces[index] = spacetest.NewSpace(commontest.HostOperatorNs, fmt.Sprintf("%s%d", prefix, index), spacetest.WithSpecTargetCluster(targetCluster)) } return spaces } diff --git a/test/spacebinding/spacebinding.go b/test/spacebinding/spacebinding.go index d82b08412..5776c530e 100644 --- a/test/spacebinding/spacebinding.go +++ b/test/spacebinding/spacebinding.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/codeready-toolchain/api/api/v1alpha1" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/test" "github.com/redhat-cop/operator-utils/pkg/util" @@ -13,18 +12,18 @@ import ( type Option func(spaceRequest *toolchainv1alpha1.SpaceBinding) -func NewSpaceBinding(mur, space, spaceRole, creator string, options ...Option) *v1alpha1.SpaceBinding { - sb := &v1alpha1.SpaceBinding{ +func NewSpaceBinding(mur, space, spaceRole, creator string, options ...Option) *toolchainv1alpha1.SpaceBinding { + sb := &toolchainv1alpha1.SpaceBinding{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-%s", mur, space), Namespace: test.HostOperatorNs, Labels: map[string]string{ - v1alpha1.SpaceCreatorLabelKey: creator, - v1alpha1.SpaceBindingMasterUserRecordLabelKey: mur, - v1alpha1.SpaceBindingSpaceLabelKey: space, + toolchainv1alpha1.SpaceCreatorLabelKey: creator, + toolchainv1alpha1.SpaceBindingMasterUserRecordLabelKey: mur, + toolchainv1alpha1.SpaceBindingSpaceLabelKey: space, }, }, - Spec: v1alpha1.SpaceBindingSpec{ + Spec: toolchainv1alpha1.SpaceBindingSpec{ MasterUserRecord: mur, Space: space, SpaceRole: spaceRole,