From d263d20129caa6bf28f09ce20b1b9c2513bbe730 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Thu, 27 Mar 2025 11:22:58 +0100 Subject: [PATCH 1/2] chore(build): migrate to golangci-lint@v2 and golangci-lint-action@v7 upgraded `.golangci.yml` with `golangci-lint migrate` include fixes suggested by `golangci-lint run -c ./.golangci.yml` Signed-off-by: Xavier Coulon --- .github/workflows/ci-golang-sbom.yml | 4 +- .golangci.yml | 92 +++++++++++++------ cmd/main.go | 11 ++- .../deactivation/deactivation_controller.go | 2 +- .../deactivation_controller_test.go | 14 +-- .../masteruserrecord_controller_test.go | 6 +- controllers/masteruserrecord/sync_test.go | 2 +- .../nstemplatetier_controller_test.go | 6 +- ...tetier_revision_cleanup_controller_test.go | 5 +- .../socialevent/socialevent_controller.go | 10 +- .../socialevent_controller_test.go | 7 +- controllers/space/space_controller_test.go | 12 +-- .../spacebinding_cleanup_controller.go | 6 +- .../spacebinding_cleanup_controller_test.go | 71 +++++++------- .../spacebindingrequest_controller.go | 2 +- .../spacebindingrequest_controller_test.go | 4 +- .../space_completion_controller_test.go | 2 +- .../spaceprovisionerconfig_controller_test.go | 6 +- .../spacerequest/spacerequest_controller.go | 2 +- .../spacerequest_controller_test.go | 4 +- .../toolchainstatus_controller_test.go | 16 ++-- controllers/usersignup/approval_test.go | 27 +++--- .../usersignup/usersignup_controller_test.go | 7 +- .../usersignup_cleanup_controller.go | 4 +- pkg/capacity/manager_test.go | 2 +- pkg/space/space_test.go | 5 +- .../notification_generator.go | 2 +- pkg/templates/usertiers/usertier_generator.go | 4 +- .../usertiers/usertier_generator_test.go | 4 +- .../usertier_generator_whitebox_test.go | 4 +- test/cluster.go | 2 +- test/configmap_assertions.go | 2 +- 32 files changed, 190 insertions(+), 157 deletions(-) diff --git a/.github/workflows/ci-golang-sbom.yml b/.github/workflows/ci-golang-sbom.yml index 926eb3201..21c6ccf20 100644 --- a/.github/workflows/ci-golang-sbom.yml +++ b/.github/workflows/ci-golang-sbom.yml @@ -27,9 +27,9 @@ jobs: make generate - name: Lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.1 + version: v2.0.2 skip-pkg-cache: true skip-build-cache: true args: --config=./.golangci.yml --verbose diff --git a/.golangci.yml b/.golangci.yml index 3d3a5845a..b0fba9596 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,34 +1,66 @@ -run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 10m - +version: "2" linters: enable: - - megacheck + - asasalint + - asciicheck + - bidichk + - bodyclose + - durationcheck + - errchkjson + - errorlint + - exhaustive + - gocheckcompilerdirectives + - gochecksumtype - gocyclo - - gofmt - - revive + - gosec + - gosmopolitan + - loggercheck + - makezero - misspell - presets: # groups of linters. See https://golangci-lint.run/usage/linters/ - - bugs - - unused - disable: - - golint # deprecated, use 'revive' - - scopelint # deprecated, use 'exportloopref' - - contextcheck # too many false-positives - - noctx # not needed - -# all available settings of specific linters -linters-settings: - unparam: - # Inspect exported functions, default is false. Set to true if no external program/library imports your code. - # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find external interfaces. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: true - revive: - rules: - - name: dot-imports - disabled: true # we allow for dot-imports - - + - musttag + - nilerr + - nilnesserr + - protogetter + - reassign + - recvcheck + - revive + - rowserrcheck + - spancheck + - sqlclosecheck + - testifylint + - unparam + - zerologlint + disable: + - contextcheck + - noctx + settings: + revive: + rules: + - name: dot-imports + disabled: true + staticcheck: + # see https://golangci-lint.run/usage/linters/#staticcheck + # we allow for dot-imports + checks: ["all", "-ST1000", "-ST1001", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"] + unparam: + check-exported: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/cmd/main.go b/cmd/main.go index fa1af4caa..528702f1f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -515,15 +515,16 @@ func (kw klogWriter) Write(p []byte) (n int, err error) { klogv2.InfoDepth(OutputCallDepth, string(p)) return len(p), nil } - if p[0] == 'I' { + switch p[0] { + case 'I': klogv2.InfoDepth(OutputCallDepth, string(p[DefaultPrefixLength:])) - } else if p[0] == 'W' { + case 'W': klogv2.WarningDepth(OutputCallDepth, string(p[DefaultPrefixLength:])) - } else if p[0] == 'E' { + case 'E': klogv2.ErrorDepth(OutputCallDepth, string(p[DefaultPrefixLength:])) - } else if p[0] == 'F' { + case 'F': klogv2.FatalDepth(OutputCallDepth, string(p[DefaultPrefixLength:])) - } else { + default: klogv2.InfoDepth(OutputCallDepth, string(p[DefaultPrefixLength:])) } return len(p), nil diff --git a/controllers/deactivation/deactivation_controller.go b/controllers/deactivation/deactivation_controller.go index e759af564..8f9cc0576 100644 --- a/controllers/deactivation/deactivation_controller.go +++ b/controllers/deactivation/deactivation_controller.go @@ -248,7 +248,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // in some rare circumstances the deactivating notification/status may fail to be set due to cluster downtime or // other reasons. Because of this, the scheduled deactivation time that is set in the UserSignup.Status should be // treated as informational only. - deactivationDueTime := deactivatingCondition.LastTransitionTime.Time.Add(time.Duration(deactivatingNotificationDays*24) * time.Hour) + deactivationDueTime := deactivatingCondition.LastTransitionTime.Add(time.Duration(deactivatingNotificationDays*24) * time.Hour) if time.Now().Before(deactivationDueTime) { // Update the ScheduledDeactivationTimestamp to the recalculated time base on when the deactivating notification was sent diff --git a/controllers/deactivation/deactivation_controller_test.go b/controllers/deactivation/deactivation_controller_test.go index e3e5e33c2..bcaaf4491 100644 --- a/controllers/deactivation/deactivation_controller_test.go +++ b/controllers/deactivation/deactivation_controller_test.go @@ -80,7 +80,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return cl.Client.Status().Update(ctx, obj) + return cl.Status().Update(ctx, obj) } } @@ -169,7 +169,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return fakeClient.Client.Status().Update(ctx, obj) + return fakeClient.Status().Update(ctx, obj) } } @@ -266,7 +266,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return cl.Client.Status().Update(ctx, obj) + return cl.Status().Update(ctx, obj) } } @@ -315,7 +315,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return cl.Client.Status().Update(ctx, obj) + return cl.Status().Update(ctx, obj) } } @@ -355,7 +355,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return cl.Client.Status().Update(ctx, obj) + return cl.Status().Update(ctx, obj) } } @@ -410,7 +410,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return cl.Client.Status().Update(ctx, obj) + return cl.Status().Update(ctx, obj) } } @@ -664,7 +664,7 @@ func TestReconcile(t *testing.T) { case *toolchainv1alpha1.UserSignup: return errors.New("mock error") default: - return fakeClient.Client.Status().Update(ctx, obj) + return fakeClient.Status().Update(ctx, obj) } } diff --git a/controllers/masteruserrecord/masteruserrecord_controller_test.go b/controllers/masteruserrecord/masteruserrecord_controller_test.go index 56874e490..e7b2d6a5e 100644 --- a/controllers/masteruserrecord/masteruserrecord_controller_test.go +++ b/controllers/masteruserrecord/masteruserrecord_controller_test.go @@ -845,7 +845,7 @@ func TestCreateSynchronizeOrDeleteUserAccountFailed(t *testing.T) { if ua, ok := obj.(*toolchainv1alpha1.UserAccount); ok { return fmt.Errorf("unable to update user account %s", ua.Name) } - return memberClient.Client.Update(ctx, obj, opts...) + return memberClient.Update(ctx, obj, opts...) } otherTier := tiertest.OtherTier(t) modifiedMur := murtest.NewMasterUserRecord(t, "john", @@ -1257,7 +1257,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) { // remove finalizer on UserAcc to delete userAcc.SetFinalizers(nil) - err = memberClient.Client.Update(context.TODO(), userAcc) + err = memberClient.Update(context.TODO(), userAcc) require.NoError(t, err) result2, err2 := cntrl.Reconcile(context.TODO(), newMurRequest(mur)) @@ -1445,7 +1445,7 @@ func TestDisablingMasterUserRecord(t *testing.T) { func newMurRequest(mur *toolchainv1alpha1.MasterUserRecord) reconcile.Request { return reconcile.Request{ - NamespacedName: namespacedName(mur.ObjectMeta.Namespace, mur.ObjectMeta.Name), + NamespacedName: namespacedName(mur.Namespace, mur.Name), } } diff --git a/controllers/masteruserrecord/sync_test.go b/controllers/masteruserrecord/sync_test.go index 5db7160fb..4f56cc286 100644 --- a/controllers/masteruserrecord/sync_test.go +++ b/controllers/masteruserrecord/sync_test.go @@ -565,7 +565,7 @@ func TestAlignReadiness(t *testing.T) { // then require.NoError(t, err) assert.True(t, ready) - require.True(t, preAlignTime.Time.After(mur.Status.ProvisionedTime.Time), "the timestamp just before syncing should be after the ProvisionedTime because this is simulating the case where the record was already provisioned before") + require.True(t, preAlignTime.After(mur.Status.ProvisionedTime.Time), "the timestamp just before syncing should be after the ProvisionedTime because this is simulating the case where the record was already provisioned before") assert.Equal(t, provisionTime.Time, mur.Status.ProvisionedTime.Time) // timestamp should be the same murtest.AssertThatMasterUserRecord(t, "john", test.NewFakeClient(t, mur)). HasConditions(toBeProvisioned(), toBeProvisionedNotificationCreated()). diff --git a/controllers/nstemplatetier/nstemplatetier_controller_test.go b/controllers/nstemplatetier/nstemplatetier_controller_test.go index 23aa79499..9f2dd66b3 100644 --- a/controllers/nstemplatetier/nstemplatetier_controller_test.go +++ b/controllers/nstemplatetier/nstemplatetier_controller_test.go @@ -48,7 +48,7 @@ func TestReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return errors.NewNotFound(schema.GroupResource{}, key.Name) } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when res, err := r.Reconcile(context.TODO(), req) @@ -65,7 +65,7 @@ func TestReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when res, err := r.Reconcile(context.TODO(), req) @@ -302,7 +302,7 @@ func TestReconcile(t *testing.T) { return fmt.Errorf("should not call Get more than once") } called = true - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } cl.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { return fmt.Errorf("should not call Create") diff --git a/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go b/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go index 0dd7ac422..f23f2ca6a 100644 --- a/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go +++ b/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - "github.com/codeready-toolchain/api/api/v1alpha1" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/host-operator/controllers/nstemplatetierrevisioncleanup" "github.com/codeready-toolchain/host-operator/pkg/apis" @@ -48,7 +47,7 @@ func TestTTRDeletionReconcile(t *testing.T) { ttr.DeletionTimestamp = &metav1.Time{ Time: time.Now(), } - controllerutil.AddFinalizer(ttr, v1alpha1.FinalizerName) + controllerutil.AddFinalizer(ttr, toolchainv1alpha1.FinalizerName) r, req, cl := prepareReconcile(t, ttr.Name, ttr, s, nsTemplateTier) //when res, err := r.Reconcile(context.TODO(), req) @@ -165,7 +164,7 @@ func TestTTRDeletionReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } //when _, err := r.Reconcile(context.TODO(), req) diff --git a/controllers/socialevent/socialevent_controller.go b/controllers/socialevent/socialevent_controller.go index 92ad0ddbd..bbb17ca2e 100644 --- a/controllers/socialevent/socialevent_controller.go +++ b/controllers/socialevent/socialevent_controller.go @@ -49,7 +49,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // fetch the SocialEvent resource event := &toolchainv1alpha1.SocialEvent{} - if err := r.Client.Get(ctx, request.NamespacedName, event); err != nil { + if err := r.Get(ctx, request.NamespacedName, event); err != nil { if errors.IsNotFound(err) { logger.Info("SocialEvent not found") return reconcile.Result{}, nil @@ -65,7 +65,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // count the number of UserSignups with the `toolchain.dev.openshift.com/social-event` label matching the SocialEvent.Name // and update the SocialEvent.Status.ActivationCount accordingly usersignups := &toolchainv1alpha1.UserSignupList{} - if err := r.Client.List(ctx, usersignups, + if err := r.List(ctx, usersignups, runtimeclient.InNamespace(r.Namespace), runtimeclient.MatchingLabels{ toolchainv1alpha1.SocialEventUserSignupLabelKey: event.Name, @@ -75,7 +75,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. } logger.Info("approved usersignups with activation code", "count", len(usersignups.Items)) event.Status.ActivationCount = len(usersignups.Items) - if err := r.Client.Status().Update(ctx, event); err != nil { + if err := r.Status().Update(ctx, event); err != nil { return reconcile.Result{}, errs.Wrap(err, "unable to update status with activation count") } return reconcile.Result{}, nil @@ -84,7 +84,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. func (r *Reconciler) checkTier(ctx context.Context, event *toolchainv1alpha1.SocialEvent) error { // fetch the UserTier specified in the SocialEvent userTier := &toolchainv1alpha1.UserTier{} - if err := r.Client.Get(ctx, types.NamespacedName{ + if err := r.Get(ctx, types.NamespacedName{ Namespace: event.Namespace, Name: event.Spec.UserTier, }, userTier); err != nil { @@ -97,7 +97,7 @@ func (r *Reconciler) checkTier(ctx context.Context, event *toolchainv1alpha1.Soc // fetch the NSTemplateTier specified in the SocialEvent spaceTier := &toolchainv1alpha1.NSTemplateTier{} - if err := r.Client.Get(ctx, types.NamespacedName{ + if err := r.Get(ctx, types.NamespacedName{ Namespace: event.Namespace, Name: event.Spec.SpaceTier, }, spaceTier); err != nil { diff --git a/controllers/socialevent/socialevent_controller_test.go b/controllers/socialevent/socialevent_controller_test.go index 47e68b33c..bda0d3d2e 100644 --- a/controllers/socialevent/socialevent_controller_test.go +++ b/controllers/socialevent/socialevent_controller_test.go @@ -3,9 +3,10 @@ package socialevent_test import ( "context" "fmt" - commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier" "testing" + commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier" + toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/host-operator/controllers/socialevent" "github.com/codeready-toolchain/host-operator/pkg/apis" @@ -95,7 +96,7 @@ func TestReconcileSocialEvent(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.UserTier); ok && key.Name == "notfound" { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(hostClient) @@ -144,7 +145,7 @@ func TestReconcileSocialEvent(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok && key.Name == "notfound" { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(hostClient) diff --git a/controllers/space/space_controller_test.go b/controllers/space/space_controller_test.go index 19ffb0b55..abfc2f0d2 100644 --- a/controllers/space/space_controller_test.go +++ b/controllers/space/space_controller_test.go @@ -327,7 +327,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithTenantRole(t, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -408,7 +408,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithTenantRole(t, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -441,7 +441,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateSet); ok { return fmt.Errorf("mock error") } - return member1Client.Client.Get(ctx, key, obj, opts...) + return member1Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -823,7 +823,7 @@ func TestDeleteSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateSet); ok { return fmt.Errorf("mock error") } - return member1Client.Client.Get(ctx, key, obj, opts...) + return member1Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -1017,7 +1017,7 @@ func TestUpdateSpaceTier(t *testing.T) { // but MORE than 1s after the Space Ready condition was set to `Ready=false/Updating` // hack: change Space's condition timestamp - s.Status.Conditions[0].LastTransitionTime = metav1.NewTime(s.Status.Conditions[0].LastTransitionTime.Time.Add(-1 * time.Second)) + s.Status.Conditions[0].LastTransitionTime = metav1.NewTime(s.Status.Conditions[0].LastTransitionTime.Add(-1 * time.Second)) err := hostClient.Status().Update(context.TODO(), s) require.NoError(t, err) @@ -1106,7 +1106,7 @@ func TestUpdateSpaceTier(t *testing.T) { err := member1.Client.Update(context.TODO(), nsTmplSet) require.NoError(t, err) // hack: change Space's updating condition timestamp so that it appears the status is ready for >1 second since it's required before can go to Ready condition - s.Status.Conditions[0].LastTransitionTime = metav1.NewTime(s.Status.Conditions[0].LastTransitionTime.Time.Add(-1 * time.Second)) + s.Status.Conditions[0].LastTransitionTime = metav1.NewTime(s.Status.Conditions[0].LastTransitionTime.Add(-1 * time.Second)) err = hostClient.Status().Update(context.TODO(), s) require.NoError(t, err) diff --git a/controllers/spacebindingcleanup/spacebinding_cleanup_controller.go b/controllers/spacebindingcleanup/spacebinding_cleanup_controller.go index 17780a1b2..c3b82a827 100644 --- a/controllers/spacebindingcleanup/spacebinding_cleanup_controller.go +++ b/controllers/spacebindingcleanup/spacebinding_cleanup_controller.go @@ -59,7 +59,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // Fetch the SpaceBinding instance spaceBinding := &toolchainv1alpha1.SpaceBinding{} - err := r.Client.Get(ctx, request.NamespacedName, spaceBinding) + err := r.Get(ctx, request.NamespacedName, spaceBinding) if err != nil { if errors.IsNotFound(err) { // Request object not found, could have been deleted after reconcile request. @@ -77,7 +77,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // ensure the space exists spaceName := types.NamespacedName{Namespace: spaceBinding.Namespace, Name: spaceBinding.Spec.Space} space := &toolchainv1alpha1.Space{} - if err := r.Client.Get(ctx, spaceName, space); err != nil { + if err := r.Get(ctx, spaceName, space); err != nil { if errors.IsNotFound(err) { logger.Info("the Space was not found", "Space", spaceBinding.Spec.Space) requeueAfter, err := r.deleteSpaceBinding(ctx, spaceBinding) @@ -110,7 +110,7 @@ func (r *Reconciler) ensureMURExists(ctx context.Context, spaceBinding *toolchai // ensure that MUR exists: if it does not exist, then delete the SpaceBinding murName := types.NamespacedName{Namespace: spaceBinding.Namespace, Name: spaceBinding.Spec.MasterUserRecord} mur := &toolchainv1alpha1.MasterUserRecord{} - if err := r.Client.Get(ctx, murName, mur); err != nil { + if err := r.Get(ctx, murName, mur); err != nil { if errors.IsNotFound(err) { logger.Info("the MUR was not found", "MasterUserRecord", spaceBinding.Spec.MasterUserRecord) return r.deleteSpaceBinding(ctx, spaceBinding) diff --git a/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go b/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go index 35d4fd59f..90a71bc5a 100644 --- a/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go +++ b/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go @@ -4,17 +4,16 @@ import ( "context" "fmt" "os" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "testing" "time" - "github.com/codeready-toolchain/api/api/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/host-operator/pkg/apis" "github.com/codeready-toolchain/host-operator/pkg/cluster" . "github.com/codeready-toolchain/host-operator/test" "github.com/codeready-toolchain/host-operator/test/spacebinding" - sb "github.com/codeready-toolchain/host-operator/test/spacebinding" commoncluster "github.com/codeready-toolchain/toolchain-common/pkg/cluster" commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration" "github.com/codeready-toolchain/toolchain-common/pkg/test" @@ -41,18 +40,18 @@ func TestDeleteSpaceBindingForKubeSawAuthenticated(t *testing.T) { { name: "with public-viewer disabled kubesaw-authenticated SpaceBinding is removed when MUR is missing", toolchainConfigOption: testconfig.PublicViewerConfig(false), - spaceBindingAssert: func(assertion *sb.Assertion) { assertion.DoesNotExist() }, + spaceBindingAssert: func(assertion *spacebinding.Assertion) { assertion.DoesNotExist() }, }, { name: "with public-viewer enabled kubesaw-authenticated SpaceBinding is NOT removed when MUR is missing", toolchainConfigOption: testconfig.PublicViewerConfig(true), - spaceBindingAssert: func(assertion *sb.Assertion) { assertion.Exists() }, + spaceBindingAssert: func(assertion *spacebinding.Assertion) { assertion.Exists() }, }, } redhatSpace := spacetest.NewSpace(test.HostOperatorNs, "redhat") - sbPublicViewerRedhatView := sb.NewSpaceBinding(toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", "view", "signupD") + sbPublicViewerRedhatView := spacebinding.NewSpaceBinding(toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", "view", "signupD") for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { @@ -68,7 +67,7 @@ func TestDeleteSpaceBindingForKubeSawAuthenticated(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - tc.spaceBindingAssert(sb.AssertThatSpaceBinding(t, test.HostOperatorNs, toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", fakeClient)) + tc.spaceBindingAssert(spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", fakeClient)) }) } } @@ -92,9 +91,9 @@ func TestDeleteSpaceBinding(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // given - sbLaraRedhatAdmin := sb.NewSpaceBinding("lara", "redhat", "admin", "signupA") - sbJoeRedhatView := sb.NewSpaceBinding("joe", "redhat", "view", "signupB") - sbLaraIbmEdit := sb.NewSpaceBinding("lara", "ibm", "edit", "signupC") + sbLaraRedhatAdmin := spacebinding.NewSpaceBinding("lara", "redhat", "admin", "signupA") + sbJoeRedhatView := spacebinding.NewSpaceBinding("joe", "redhat", "view", "signupB") + sbLaraIbmEdit := spacebinding.NewSpaceBinding("lara", "ibm", "edit", "signupC") redhatSpace := spacetest.NewSpace(test.HostOperatorNs, "redhat") ibmSpace := spacetest.NewSpace(test.HostOperatorNs, "ibm") @@ -102,7 +101,7 @@ func TestDeleteSpaceBinding(t *testing.T) { laraMur := masteruserrecord.NewMasterUserRecord(t, "lara") joeMur := masteruserrecord.NewMasterUserRecord(t, "joe") - sbPublicViewerRedhatView := sb.NewSpaceBinding(toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", "view", "signupD") + sbPublicViewerRedhatView := spacebinding.NewSpaceBinding(toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", "view", "signupD") toolchainconfig := commonconfig.NewToolchainConfigObjWithReset(t, tc.toolchainConfigOption) t.Run("error retrieving the ToolchainConfig", func(t *testing.T) { @@ -128,7 +127,7 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", fakeClient).DoesNotExist() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, toolchainv1alpha1.KubesawAuthenticatedUsername, "redhat", fakeClient).DoesNotExist() }) t.Run("lara-redhat SpaceBinding removed when redhat space is missing", func(t *testing.T) { @@ -141,9 +140,9 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).DoesNotExist() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).DoesNotExist() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() }) t.Run("joe-redhat SpaceBinding removed when joe MUR is missing", func(t *testing.T) { @@ -157,16 +156,16 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).DoesNotExist() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).DoesNotExist() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() }) t.Run("lara-redhat SpaceBinding is being deleted, so no action needed", func(t *testing.T) { sbLaraRedhatAdmin := sbLaraRedhatAdmin.DeepCopy() now := metav1.Now() sbLaraRedhatAdmin.DeletionTimestamp = &now - controllerutil.AddFinalizer(sbLaraRedhatAdmin, v1alpha1.FinalizerName) + controllerutil.AddFinalizer(sbLaraRedhatAdmin, toolchainv1alpha1.FinalizerName) fakeClient := test.NewFakeClient(t, sbLaraRedhatAdmin, sbJoeRedhatView, sbLaraIbmEdit, laraMur, joeMur, ibmSpace, toolchainconfig) reconciler := prepareReconciler(t, fakeClient) @@ -176,9 +175,9 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() }) t.Run("no SpaceBinding removed when MUR and Space are present", func(t *testing.T) { @@ -192,9 +191,9 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "joe", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "ibm", fakeClient).Exists() }) t.Run("fails while getting the bound resource", func(t *testing.T) { @@ -206,7 +205,7 @@ func TestDeleteSpaceBinding(t *testing.T) { if key.Name == boundResourceName { return fmt.Errorf("some error") } - return fakeClient.Client.Get(ctx, key, obj, opts...) + return fakeClient.Get(ctx, key, obj, opts...) } // when @@ -214,7 +213,7 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Error(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() } }) @@ -231,7 +230,7 @@ func TestDeleteSpaceBinding(t *testing.T) { // then require.Error(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "redhat", fakeClient).Exists() }) }) } @@ -262,7 +261,7 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { sbr := sbrtestcommon.NewSpaceBindingRequest("lara", "lara-tenant", sbrtestcommon.WithMUR("lara"), sbrtestcommon.WithSpaceRole("admin")) - sbLaraAdmin := sb.NewSpaceBinding("lara", "lara", "admin", sbr.GetName(), sb.WithSpaceBindingRequest(sbr)) // the spacebinding was created from spacebindingrequest + sbLaraAdmin := spacebinding.NewSpaceBinding("lara", "lara", "admin", sbr.GetName(), spacebinding.WithSpaceBindingRequest(sbr)) // the spacebinding was created from spacebindingrequest t.Run("SpaceBindingRequest is deleted", func(t *testing.T) { // given member1 := NewMemberClusterWithClient(test.NewFakeClient(t, sbr), "member-1", corev1.ConditionTrue) @@ -290,14 +289,14 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { // then require.Equal(t, res.RequeueAfter, time.Duration(0)) // no requeue require.NoError(t, err) - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).DoesNotExist() // the spacebinding is deleted + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).DoesNotExist() // the spacebinding is deleted }) t.Run("unable to get SpaceBindingRequest", func(t *testing.T) { // given member1Client := test.NewFakeClient(t) member1Client.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error { - if _, ok := obj.(*v1alpha1.SpaceBindingRequest); ok { + if _, ok := obj.(*toolchainv1alpha1.SpaceBindingRequest); ok { return fmt.Errorf("mock error") } return member1Client.Get(ctx, key, obj, opts...) @@ -310,15 +309,15 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { _, err := reconciler.Reconcile(context.TODO(), requestFor(sbLaraAdmin)) // then - require.EqualError(t, err, "unable to get the current *v1alpha1.SpaceBindingRequest: mock error") - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).Exists() // the spacebinding is not deleted yet + require.EqualError(t, err, "unable to get the current *toolchainv1alpha1.SpaceBindingRequest: mock error") + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).Exists() // the spacebinding is not deleted yet }) t.Run("fails while deleting the SpaceBindingRequest", func(t *testing.T) { // given member1Client := test.NewFakeClient(t, sbr) member1Client.MockDelete = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.DeleteOption) error { - if _, ok := obj.(*v1alpha1.SpaceBindingRequest); ok { + if _, ok := obj.(*toolchainv1alpha1.SpaceBindingRequest); ok { return fmt.Errorf("mock error") } return member1Client.Client.Delete(ctx, obj, opts...) @@ -332,7 +331,7 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { // then require.EqualError(t, err, "unable to delete the SpaceBindingRequest: mock error") - sb.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).Exists() // the spacebinding is not deleted yet + spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).Exists() // the spacebinding is not deleted yet }) }) } @@ -364,7 +363,7 @@ func prepareReconciler(t *testing.T, hostCl runtimeclient.Client, memberClusters return reconciler } -func requestFor(s *v1alpha1.SpaceBinding) reconcile.Request { +func requestFor(s *toolchainv1alpha1.SpaceBinding) reconcile.Request { if s != nil { return reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/controllers/spacebindingrequest/spacebindingrequest_controller.go b/controllers/spacebindingrequest/spacebindingrequest_controller.go index 0caea13c7..7fdbcc502 100644 --- a/controllers/spacebindingrequest/spacebindingrequest_controller.go +++ b/controllers/spacebindingrequest/spacebindingrequest_controller.go @@ -229,7 +229,7 @@ func (r *Reconciler) ensureSpaceBinding(ctx context.Context, memberCluster clust // check if existing spacebinding was created from spaceBindingRequest // and return an error in case it was not. if spaceBinding != nil && !sbrOwnsSpaceBinding(spaceBinding, spaceBindingRequest) { - return fmt.Errorf("A SpaceBinding for Space '%s' and MUR '%s' already exists, but it's not managed by this SpaceBindingRequest CR. It's not allowed to create multiple SpaceBindings for the same combination of Space and MasterUserRecord", space.GetName(), spaceBindingRequest.Spec.MasterUserRecord) + return fmt.Errorf("a SpaceBinding for Space '%s' and MUR '%s' already exists, but it's not managed by this SpaceBindingRequest CR. It's not allowed to create multiple SpaceBindings for the same combination of Space and MasterUserRecord", space.GetName(), spaceBindingRequest.Spec.MasterUserRecord) } // space is being deleted diff --git a/controllers/spacebindingrequest/spacebindingrequest_controller_test.go b/controllers/spacebindingrequest/spacebindingrequest_controller_test.go index 70378dbd5..89999abc3 100644 --- a/controllers/spacebindingrequest/spacebindingrequest_controller_test.go +++ b/controllers/spacebindingrequest/spacebindingrequest_controller_test.go @@ -293,7 +293,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) @@ -339,7 +339,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.MasterUserRecord); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) diff --git a/controllers/spacecompletion/space_completion_controller_test.go b/controllers/spacecompletion/space_completion_controller_test.go index 4d713758a..fd64a4fe9 100644 --- a/controllers/spacecompletion/space_completion_controller_test.go +++ b/controllers/spacecompletion/space_completion_controller_test.go @@ -175,7 +175,7 @@ func TestCreateSpace(t *testing.T) { if key.Name == "config" { return fmt.Errorf("some error") } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when diff --git a/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go b/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go index 56e47d271..b9b6b9e7c 100644 --- a/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go +++ b/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go @@ -328,7 +328,7 @@ func TestSpaceProvisionerConfigReEnqueing(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainCluster); ok { return getErr } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when @@ -398,7 +398,7 @@ func TestSpaceProvisionerConfigReEnqueing(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainCluster); ok { return &kerrors.StatusError{ErrStatus: metav1.Status{Reason: metav1.StatusReasonNotFound}} } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when @@ -481,7 +481,7 @@ func TestCollectConsumedCapacity(t *testing.T) { if key.Name == "toolchain-status" { return errors.New("intetionally failing") } - return cl.Client.Get(ctx, key, obj, opts...) + return cl.Get(ctx, key, obj, opts...) } // when diff --git a/controllers/spacerequest/spacerequest_controller.go b/controllers/spacerequest/spacerequest_controller.go index 3117c1c6e..8f9922365 100644 --- a/controllers/spacerequest/spacerequest_controller.go +++ b/controllers/spacerequest/spacerequest_controller.go @@ -570,7 +570,7 @@ func (r *Reconciler) generateKubeConfig(ctx context.Context, subSpaceTargetClust // create apiConfig based on the secret content clusters := make(map[string]*api.Cluster, 1) clusters["default-cluster"] = &api.Cluster{ - Server: subSpaceTargetCluster.Config.APIEndpoint, + Server: subSpaceTargetCluster.APIEndpoint, CertificateAuthorityData: subSpaceTargetCluster.RestConfig.CAData, InsecureSkipTLSVerify: subSpaceTargetCluster.RestConfig.Insecure, } diff --git a/controllers/spacerequest/spacerequest_controller_test.go b/controllers/spacerequest/spacerequest_controller_test.go index 40d10dcc8..704d73a1a 100644 --- a/controllers/spacerequest/spacerequest_controller_test.go +++ b/controllers/spacerequest/spacerequest_controller_test.go @@ -923,7 +923,7 @@ func TestCreateSpaceRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) @@ -1037,7 +1037,7 @@ func TestCreateSpaceRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Client.Get(ctx, key, obj, opts...) + return hostClient.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) diff --git a/controllers/toolchainstatus/toolchainstatus_controller_test.go b/controllers/toolchainstatus/toolchainstatus_controller_test.go index 402b53096..e28049b2e 100644 --- a/controllers/toolchainstatus/toolchainstatus_controller_test.go +++ b/controllers/toolchainstatus/toolchainstatus_controller_test.go @@ -150,7 +150,7 @@ func TestNoToolchainStatusFound(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainStatus); ok { return fmt.Errorf("get failed") } - return fakeClient.Client.Get(ctx, key, obj, opts...) + return fakeClient.Get(ctx, key, obj, opts...) } // when @@ -1250,7 +1250,7 @@ func TestToolchainStatusNotifications(t *testing.T) { assertToolchainStatusNotificationNotCreated(t, fakeClient, restoredStatusNotification) // Confirm the unready notification has been created notification := assertToolchainStatusNotificationCreated(t, fakeClient) - require.True(t, strings.HasPrefix(notification.ObjectMeta.Name, "toolchainstatus-unready-")) + require.True(t, strings.HasPrefix(notification.Name, "toolchainstatus-unready-")) require.NotNil(t, notification) require.Equal(t, "ToolchainStatus has been in an unready status for an extended period for host-cluster", notification.Spec.Subject) @@ -1279,7 +1279,7 @@ func TestToolchainStatusNotifications(t *testing.T) { // Confirm restored notification has been created notification := assertToolchainStatusNotificationCreated(t, fakeClient) - require.True(t, strings.HasPrefix(notification.ObjectMeta.Name, "toolchainstatus-restored-")) + require.True(t, strings.HasPrefix(notification.Name, "toolchainstatus-restored-")) fmt.Println(notification) require.NotNil(t, notification) @@ -1385,8 +1385,8 @@ func TestToolchainStatusNotifications(t *testing.T) { } func assertToolChainNotificationUnreadyStatus(t *testing.T, invalidURL bool, notification *toolchainv1alpha1.Notification, email string) { - require.True(t, strings.HasPrefix(notification.ObjectMeta.Name, "toolchainstatus-unready-")) - require.Len(t, notification.ObjectMeta.Name, 38) + require.True(t, strings.HasPrefix(notification.Name, "toolchainstatus-unready-")) + require.Len(t, notification.Name, 38) require.NotNil(t, notification) if invalidURL { assert.Equal(t, "ToolchainStatus has been in an unready status for an extended period for ", notification.Spec.Subject) @@ -1430,7 +1430,7 @@ func assertToolchainStatusNotificationNotCreated(t *testing.T, fakeClient *test. }) require.NoError(t, err) for _, notification := range notifications.Items { - require.False(t, strings.HasPrefix(notification.ObjectMeta.Name, notificationType)) + require.False(t, strings.HasPrefix(notification.Name, notificationType)) } } @@ -1580,7 +1580,7 @@ func TestExtractStatusMetadata(t *testing.T) { meta := ExtractStatusMetadata(toolchainStatus) require.Len(t, meta, 1) - require.Equal(t, "", meta[0].ComponentType) + require.Empty(t, meta[0].ComponentType) require.Equal(t, "SomeReason", meta[0].Reason) require.Equal(t, "A message", meta[0].Message) require.Equal(t, "ToolchainStatus", meta[0].ComponentName) @@ -1828,7 +1828,7 @@ func TestRemoveSchemeFromURL(t *testing.T) { domain, err := removeSchemeFromURL("incorrect$%url") // then - require.Equal(t, "", domain) + require.Empty(t, domain) require.Error(t, err) }) diff --git a/controllers/usersignup/approval_test.go b/controllers/usersignup/approval_test.go index b6d9d1bea..f7c2fb373 100644 --- a/controllers/usersignup/approval_test.go +++ b/controllers/usersignup/approval_test.go @@ -10,7 +10,6 @@ import ( . "github.com/codeready-toolchain/host-operator/test" hspc "github.com/codeready-toolchain/host-operator/test/spaceprovisionerconfig" commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration" - "github.com/codeready-toolchain/toolchain-common/pkg/test" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" commonsignup "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup" @@ -42,7 +41,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -63,7 +62,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -128,7 +127,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then if testFields.ErrorExpected { @@ -156,7 +155,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -173,7 +172,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -189,7 +188,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -205,7 +204,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -222,7 +221,7 @@ func TestGetClusterIfApproved(t *testing.T) { signup := commonsignup.NewUserSignup(commonsignup.ApprovedManually()) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -239,7 +238,7 @@ func TestGetClusterIfApproved(t *testing.T) { signup := commonsignup.NewUserSignup(commonsignup.ApprovedManually()) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -256,7 +255,7 @@ func TestGetClusterIfApproved(t *testing.T) { signup := commonsignup.NewUserSignup(commonsignup.ApprovedManually()) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -273,7 +272,7 @@ func TestGetClusterIfApproved(t *testing.T) { signup := commonsignup.NewUserSignup(commonsignup.ApprovedManually(), commonsignup.WithTargetCluster("member1")) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.NoError(t, err) @@ -291,7 +290,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.EqualError(t, err, "unable to get ToolchainConfig: some error") @@ -311,7 +310,7 @@ func TestGetClusterIfApproved(t *testing.T) { InitializeCounters(t, toolchainStatus) // when - approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(test.HostOperatorNs, fakeClient)) + approved, clusterName, err := getClusterIfApproved(ctx, fakeClient, signup, capacity.NewClusterManager(commontest.HostOperatorNs, fakeClient)) // then require.EqualError(t, err, "unable to get the optimal target cluster: failed to find the optimal space provisioner config: some error") diff --git a/controllers/usersignup/usersignup_controller_test.go b/controllers/usersignup/usersignup_controller_test.go index 8aa77784b..8d5fcf6b7 100644 --- a/controllers/usersignup/usersignup_controller_test.go +++ b/controllers/usersignup/usersignup_controller_test.go @@ -1640,10 +1640,11 @@ func TestUserSignupMUROrSpaceOrSpaceBindingCreateFails(t *testing.T) { spc1 := hspc.NewEnabledValidTenantSPC("member1") initObjs := []runtimeclient.Object{userSignup, baseNSTemplateTier, deactivate30Tier, spc1} - if testcase.testName == "create space error" { + switch testcase.testName { + case "create space error": // mur must exist first, space is created on the reconcile after the mur is created initObjs = append(initObjs, mur) - } else if testcase.testName == "create spacebinding error" { + case "create spacebinding error": // mur and space must exist first, spacebinding is created on the reconcile after the space is created initObjs = append(initObjs, mur, space) } @@ -2132,7 +2133,7 @@ func TestUserSignupPropagatedClaimsSynchronizedToMURWhenModified(t *testing.T) { require.Equal(t, mur.Spec.PropagatedClaims, userSignup.Spec.IdentityClaims.PropagatedClaims) // Modify one of the propagated claims - userSignup.Spec.IdentityClaims.PropagatedClaims.UserID = "314159265358979" + userSignup.Spec.IdentityClaims.UserID = "314159265358979" // Reconcile the UserSignup again r, req, _ = prepareReconcile(t, userSignup.Name, spc1, userSignup, deactivate30Tier) diff --git a/controllers/usersignupcleanup/usersignup_cleanup_controller.go b/controllers/usersignupcleanup/usersignup_cleanup_controller.go index 04ff97c29..8c2eb0f6b 100644 --- a/controllers/usersignupcleanup/usersignup_cleanup_controller.go +++ b/controllers/usersignupcleanup/usersignup_cleanup_controller.go @@ -92,7 +92,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // If the UserSignup has no previous activations (i.e. it's a new, never-provisioned UserSignup) then // it should be deleted if it has been in an unverified state beyond a configured period of time if !activationsAnnotationPresent || activations == "0" { - createdTime := instance.ObjectMeta.CreationTimestamp + createdTime := instance.CreationTimestamp unverifiedThreshold := time.Now().Add(-time.Duration(config.Deactivation().UserSignupUnverifiedRetentionDays()*24) * time.Hour) @@ -173,7 +173,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. // Requeue this for reconciliation after the time has passed between the last transition time // and the current deletion expiry threshold - requeueAfter := cond.LastTransitionTime.Time.Sub(deactivatedThreshold) + requeueAfter := cond.LastTransitionTime.Sub(deactivatedThreshold) // Requeue the reconciler to process this resource again after the threshold for deletion return reconcile.Result{ diff --git a/pkg/capacity/manager_test.go b/pkg/capacity/manager_test.go index 50d1c6923..863080146 100644 --- a/pkg/capacity/manager_test.go +++ b/pkg/capacity/manager_test.go @@ -215,7 +215,7 @@ func TestGetOptimalTargetCluster(t *testing.T) { // then require.EqualError(t, err, "failed to find the optimal space provisioner config: some error") - assert.Equal(t, "", clusterName) + assert.Empty(t, clusterName) }) }) } diff --git a/pkg/space/space_test.go b/pkg/space/space_test.go index c462029ac..74e57ef04 100644 --- a/pkg/space/space_test.go +++ b/pkg/space/space_test.go @@ -2,10 +2,11 @@ package space import ( "fmt" - "github.com/codeready-toolchain/host-operator/controllers/toolchainconfig" "strings" "testing" + "github.com/codeready-toolchain/host-operator/controllers/toolchainconfig" + toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" spacerequesttest "github.com/codeready-toolchain/host-operator/test/spacerequest" commoncluster "github.com/codeready-toolchain/toolchain-common/pkg/cluster" @@ -139,6 +140,6 @@ func TestNewSubSubSpace(t *testing.T) { assert.Equal(t, expectedSubSubSpace, subSubSpace) // also assert that names don't grow in length as we increase nesting - assert.Equal(t, len(subSpace.Name), len(subSubSpace.Name)) + assert.Len(t, subSubSpace.Name, len(subSpace.Name)) assert.NotEqual(t, subSpace.Name, subSubSpace.Name) } diff --git a/pkg/templates/notificationtemplates/notification_generator.go b/pkg/templates/notificationtemplates/notification_generator.go index 98d39c9a5..7d1b24f70 100644 --- a/pkg/templates/notificationtemplates/notification_generator.go +++ b/pkg/templates/notificationtemplates/notification_generator.go @@ -50,7 +50,7 @@ func templatesForAssets(notificationFS embed.FS, root string, setName string) (m return nil, err } if len(paths) == 0 { - return nil, fmt.Errorf("Could not find any emails templates for the environment %v", setName) + return nil, fmt.Errorf("could not find any emails templates for the environment %v", setName) } notificationTemplates = make(map[string]NotificationTemplate) for _, path := range paths { diff --git a/pkg/templates/usertiers/usertier_generator.go b/pkg/templates/usertiers/usertier_generator.go index 54294e163..94463668b 100644 --- a/pkg/templates/usertiers/usertier_generator.go +++ b/pkg/templates/usertiers/usertier_generator.go @@ -137,8 +137,8 @@ func loadTemplatesByTiers(assets assets.Assets) (map[string]*tierData, error) { tmpl := template{ content: content, } - switch { - case filename == "tier.yaml": + switch filename { + case "tier.yaml": results[tier].rawTemplates.userTier = &tmpl default: return nil, errors.Errorf("unable to load templates: unknown scope for file '%s'", name) diff --git a/pkg/templates/usertiers/usertier_generator_test.go b/pkg/templates/usertiers/usertier_generator_test.go index 660d836bb..dd4e9a645 100644 --- a/pkg/templates/usertiers/usertier_generator_test.go +++ b/pkg/templates/usertiers/usertier_generator_test.go @@ -58,7 +58,7 @@ func TestCreateOrUpdateResources(t *testing.T) { tier := toolchainv1alpha1.UserTier{} err = clt.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: tierName}, &tier) require.NoError(t, err) - assert.Equal(t, int64(1), tier.ObjectMeta.Generation) + assert.Equal(t, int64(1), tier.Generation) switch tierName { case "base": @@ -91,7 +91,7 @@ func TestCreateOrUpdateResources(t *testing.T) { tier := toolchainv1alpha1.UserTier{} err = clt.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: tierName}, &tier) require.NoError(t, err) - assert.Equal(t, int64(1), tier.ObjectMeta.Generation) + assert.Equal(t, int64(1), tier.Generation) switch tierName { case "advanced": diff --git a/pkg/templates/usertiers/usertier_generator_whitebox_test.go b/pkg/templates/usertiers/usertier_generator_whitebox_test.go index 135337d45..aa5207e91 100644 --- a/pkg/templates/usertiers/usertier_generator_whitebox_test.go +++ b/pkg/templates/usertiers/usertier_generator_whitebox_test.go @@ -175,8 +175,8 @@ func TestNewUserTier(t *testing.T) { tier := runtimeObjectToUserTier(t, s, tierObjs[0]) // require.True(t, found) - assert.Equal(t, name, tier.ObjectMeta.Name) - assert.Equal(t, namespace, tier.ObjectMeta.Namespace) + assert.Equal(t, name, tier.Name) + assert.Equal(t, namespace, tier.Namespace) switch name { case "nodeactivation": diff --git a/test/cluster.go b/test/cluster.go index d6f1dedff..c6d2b0d48 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -39,7 +39,7 @@ type Modifier func(toolchainCluster *cluster.CachedToolchainCluster) func WithClusterRoleLabel(labelKey string) Modifier { return func(cluster *cluster.CachedToolchainCluster) { - cluster.Config.Labels[labelKey] = "" // we don't care about the label value, only the key is used + cluster.Labels[labelKey] = "" // we don't care about the label value, only the key is used } } diff --git a/test/configmap_assertions.go b/test/configmap_assertions.go index b761ae47f..6d8ab207d 100644 --- a/test/configmap_assertions.go +++ b/test/configmap_assertions.go @@ -54,7 +54,7 @@ func (a *ConfigMapAssertion) HasOwner(owner runtime.Object) *ConfigMapAssertion func (a *ConfigMapAssertion) HasData(data map[string]string) *ConfigMapAssertion { err := a.loadConfigMap() require.NoError(a.t, err) - require.Equal(a.t, len(data), len(a.configmap.Data)) + require.Len(a.t, a.configmap.Data, len(data)) for k, v := range data { require.Contains(a.t, a.configmap.Data, k) assert.Equal(a.t, v, a.configmap.Data[k]) From b16ad65b8a1962fd3ba9f74b1936f728b48609d5 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Thu, 27 Mar 2025 12:22:47 +0100 Subject: [PATCH 2/2] fixing tests Signed-off-by: Xavier Coulon --- .../nstemplatetier/nstemplatetier_controller_test.go | 6 +++--- .../nstemplatetier_revision_cleanup_controller_test.go | 2 +- controllers/socialevent/socialevent_controller_test.go | 4 ++-- controllers/space/space_controller_test.go | 8 ++++---- .../spacebinding_cleanup_controller_test.go | 6 +++--- .../spacebindingrequest_controller_test.go | 6 +++--- .../spacecompletion/space_completion_controller_test.go | 2 +- .../spaceprovisionerconfig_controller_test.go | 6 +++--- controllers/spacerequest/spacerequest_controller_test.go | 4 ++-- .../toolchainstatus/toolchainstatus_controller_test.go | 2 +- controllers/usersignup/predicate.go | 5 ----- .../notificationtemplates/notification_generator_test.go | 2 +- 12 files changed, 24 insertions(+), 29 deletions(-) diff --git a/controllers/nstemplatetier/nstemplatetier_controller_test.go b/controllers/nstemplatetier/nstemplatetier_controller_test.go index 9f2dd66b3..23aa79499 100644 --- a/controllers/nstemplatetier/nstemplatetier_controller_test.go +++ b/controllers/nstemplatetier/nstemplatetier_controller_test.go @@ -48,7 +48,7 @@ func TestReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return errors.NewNotFound(schema.GroupResource{}, key.Name) } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when res, err := r.Reconcile(context.TODO(), req) @@ -65,7 +65,7 @@ func TestReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when res, err := r.Reconcile(context.TODO(), req) @@ -302,7 +302,7 @@ func TestReconcile(t *testing.T) { return fmt.Errorf("should not call Get more than once") } called = true - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } cl.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { return fmt.Errorf("should not call Create") diff --git a/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go b/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go index f23f2ca6a..1922a4cc8 100644 --- a/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go +++ b/controllers/nstemplatetierrevisioncleanup/nstemplatetier_revision_cleanup_controller_test.go @@ -164,7 +164,7 @@ func TestTTRDeletionReconcile(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } //when _, err := r.Reconcile(context.TODO(), req) diff --git a/controllers/socialevent/socialevent_controller_test.go b/controllers/socialevent/socialevent_controller_test.go index bda0d3d2e..66f6aaf89 100644 --- a/controllers/socialevent/socialevent_controller_test.go +++ b/controllers/socialevent/socialevent_controller_test.go @@ -96,7 +96,7 @@ func TestReconcileSocialEvent(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.UserTier); ok && key.Name == "notfound" { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(hostClient) @@ -145,7 +145,7 @@ func TestReconcileSocialEvent(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok && key.Name == "notfound" { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(hostClient) diff --git a/controllers/space/space_controller_test.go b/controllers/space/space_controller_test.go index abfc2f0d2..3822879a9 100644 --- a/controllers/space/space_controller_test.go +++ b/controllers/space/space_controller_test.go @@ -327,7 +327,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithTenantRole(t, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -408,7 +408,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithTenantRole(t, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -441,7 +441,7 @@ func TestCreateSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateSet); ok { return fmt.Errorf("mock error") } - return member1Client.Get(ctx, key, obj, opts...) + return member1Client.Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) @@ -823,7 +823,7 @@ func TestDeleteSpace(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateSet); ok { return fmt.Errorf("mock error") } - return member1Client.Get(ctx, key, obj, opts...) + return member1Client.Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) member2 := NewMemberClusterWithTenantRole(t, "member-2", corev1.ConditionTrue) diff --git a/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go b/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go index 90a71bc5a..a5aee4741 100644 --- a/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go +++ b/controllers/spacebindingcleanup/spacebinding_cleanup_controller_test.go @@ -205,7 +205,7 @@ func TestDeleteSpaceBinding(t *testing.T) { if key.Name == boundResourceName { return fmt.Errorf("some error") } - return fakeClient.Get(ctx, key, obj, opts...) + return fakeClient.Client.Get(ctx, key, obj, opts...) } // when @@ -299,7 +299,7 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.SpaceBindingRequest); ok { return fmt.Errorf("mock error") } - return member1Client.Get(ctx, key, obj, opts...) + return member1Client.Client.Get(ctx, key, obj, opts...) } member1 := NewMemberClusterWithClient(member1Client, "member-1", corev1.ConditionTrue) // for some reason spacebindingrequest is gone from member cluster hostClient := test.NewFakeClient(t, sbLaraAdmin, toolchainconfig) @@ -309,7 +309,7 @@ func TestDeleteSpaceBindingRequest(t *testing.T) { _, err := reconciler.Reconcile(context.TODO(), requestFor(sbLaraAdmin)) // then - require.EqualError(t, err, "unable to get the current *toolchainv1alpha1.SpaceBindingRequest: mock error") + require.EqualError(t, err, "unable to get the current *v1alpha1.SpaceBindingRequest: mock error") spacebinding.AssertThatSpaceBinding(t, test.HostOperatorNs, "lara", "lara", hostClient).Exists() // the spacebinding is not deleted yet }) diff --git a/controllers/spacebindingrequest/spacebindingrequest_controller_test.go b/controllers/spacebindingrequest/spacebindingrequest_controller_test.go index 89999abc3..a309b6ff9 100644 --- a/controllers/spacebindingrequest/spacebindingrequest_controller_test.go +++ b/controllers/spacebindingrequest/spacebindingrequest_controller_test.go @@ -293,7 +293,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) @@ -339,7 +339,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.MasterUserRecord); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) @@ -491,7 +491,7 @@ func TestCreateSpaceBindingRequest(t *testing.T) { _, err := ctrl.Reconcile(context.TODO(), requestFor(sbrForDuplicatedSpaceBinding)) // then - cause := fmt.Sprintf("A SpaceBinding for Space '%s' and MUR '%s' already exists, but it's not managed by this SpaceBindingRequest CR. It's not allowed to create multiple SpaceBindings for the same combination of Space and MasterUserRecord", janeSpace.GetName(), janeMur.GetName()) + cause := fmt.Sprintf("a SpaceBinding for Space '%s' and MUR '%s' already exists, but it's not managed by this SpaceBindingRequest CR. It's not allowed to create multiple SpaceBindings for the same combination of Space and MasterUserRecord", janeSpace.GetName(), janeMur.GetName()) require.EqualError(t, err, cause) sbrtestcommon.AssertThatSpaceBindingRequest(t, sbr.GetNamespace(), sbr.GetName(), member1.Client). HasConditions(sbrtestcommon.UnableToCreateSpaceBinding(cause)). diff --git a/controllers/spacecompletion/space_completion_controller_test.go b/controllers/spacecompletion/space_completion_controller_test.go index fd64a4fe9..4d713758a 100644 --- a/controllers/spacecompletion/space_completion_controller_test.go +++ b/controllers/spacecompletion/space_completion_controller_test.go @@ -175,7 +175,7 @@ func TestCreateSpace(t *testing.T) { if key.Name == "config" { return fmt.Errorf("some error") } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when diff --git a/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go b/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go index b9b6b9e7c..56e47d271 100644 --- a/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go +++ b/controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller_test.go @@ -328,7 +328,7 @@ func TestSpaceProvisionerConfigReEnqueing(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainCluster); ok { return getErr } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when @@ -398,7 +398,7 @@ func TestSpaceProvisionerConfigReEnqueing(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainCluster); ok { return &kerrors.StatusError{ErrStatus: metav1.Status{Reason: metav1.StatusReasonNotFound}} } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when @@ -481,7 +481,7 @@ func TestCollectConsumedCapacity(t *testing.T) { if key.Name == "toolchain-status" { return errors.New("intetionally failing") } - return cl.Get(ctx, key, obj, opts...) + return cl.Client.Get(ctx, key, obj, opts...) } // when diff --git a/controllers/spacerequest/spacerequest_controller_test.go b/controllers/spacerequest/spacerequest_controller_test.go index 704d73a1a..40d10dcc8 100644 --- a/controllers/spacerequest/spacerequest_controller_test.go +++ b/controllers/spacerequest/spacerequest_controller_test.go @@ -923,7 +923,7 @@ func TestCreateSpaceRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) @@ -1037,7 +1037,7 @@ func TestCreateSpaceRequest(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.Space); ok { return fmt.Errorf("mock error") } - return hostClient.Get(ctx, key, obj, opts...) + return hostClient.Client.Get(ctx, key, obj, opts...) } ctrl := newReconciler(t, hostClient, member1) diff --git a/controllers/toolchainstatus/toolchainstatus_controller_test.go b/controllers/toolchainstatus/toolchainstatus_controller_test.go index e28049b2e..f49b295c9 100644 --- a/controllers/toolchainstatus/toolchainstatus_controller_test.go +++ b/controllers/toolchainstatus/toolchainstatus_controller_test.go @@ -150,7 +150,7 @@ func TestNoToolchainStatusFound(t *testing.T) { if _, ok := obj.(*toolchainv1alpha1.ToolchainStatus); ok { return fmt.Errorf("get failed") } - return fakeClient.Get(ctx, key, obj, opts...) + return fakeClient.Client.Get(ctx, key, obj, opts...) } // when diff --git a/controllers/usersignup/predicate.go b/controllers/usersignup/predicate.go index 2e3b3af97..c73bbf112 100644 --- a/controllers/usersignup/predicate.go +++ b/controllers/usersignup/predicate.go @@ -34,11 +34,6 @@ func (p UserSignupChangedPredicate) Update(e runtimeevent.UpdateEvent) bool { p.labelChanged(e, toolchainv1alpha1.UserSignupUserEmailHashLabelKey) } -//lint:ignore U1000 -func (p UserSignupChangedPredicate) annotationChanged(e runtimeevent.UpdateEvent, annotationName string) bool { - return e.ObjectOld.GetAnnotations()[annotationName] != e.ObjectNew.GetAnnotations()[annotationName] -} - func (p UserSignupChangedPredicate) labelChanged(e runtimeevent.UpdateEvent, labelName string) bool { return e.ObjectOld.GetLabels()[labelName] != e.ObjectNew.GetLabels()[labelName] } diff --git a/pkg/templates/notificationtemplates/notification_generator_test.go b/pkg/templates/notificationtemplates/notification_generator_test.go index ded0c3a74..a2c537632 100644 --- a/pkg/templates/notificationtemplates/notification_generator_test.go +++ b/pkg/templates/notificationtemplates/notification_generator_test.go @@ -160,7 +160,7 @@ func TestTemplatesForAssets(t *testing.T) { // then require.Error(t, err) assert.Nil(t, template) - assert.Equal(t, "Could not find any emails templates for the environment alpha", err.Error()) + assert.Equal(t, "could not find any emails templates for the environment alpha", err.Error()) }) t.Run("no directory name", func(t *testing.T) { // given