diff --git a/controllers/deactivation/deactivation_controller.go b/controllers/deactivation/deactivation_controller.go index c3ce167f3..e759af564 100644 --- a/controllers/deactivation/deactivation_controller.go +++ b/controllers/deactivation/deactivation_controller.go @@ -3,11 +3,12 @@ package deactivation import ( "context" "fmt" - usersignup2 "github.com/codeready-toolchain/host-operator/controllers/usersignup" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" "time" + usersignup2 "github.com/codeready-toolchain/host-operator/controllers/usersignup" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/host-operator/controllers/toolchainconfig" "github.com/codeready-toolchain/host-operator/pkg/metrics" @@ -192,7 +193,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl. } // If the usersignup state hasn't been set to deactivating, then set it now - if !states.Deactivating(usersignup) { + if !states.Deactivating(usersignup) && deactivatingNotificationDays > 0 { // Before we update the UserSignup in order to set the deactivating state, we should reset the scheduled // deactivation time if required just in case the current value is nil or has somehow changed. Since the UserSignup diff --git a/controllers/deactivation/deactivation_controller_test.go b/controllers/deactivation/deactivation_controller_test.go index 645d3f7a0..e3e5e33c2 100644 --- a/controllers/deactivation/deactivation_controller_test.go +++ b/controllers/deactivation/deactivation_controller_test.go @@ -3,13 +3,14 @@ package deactivation import ( "context" "fmt" - commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier" - "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup" - "github.com/pkg/errors" "os" "testing" "time" + commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier" + "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup" + "github.com/pkg/errors" + "github.com/gofrs/uuid" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" @@ -763,7 +764,7 @@ func TestReconcile(t *testing.T) { }) } -func TestAutomaticDeactivation(t *testing.T) { +func TestAutomaticDeactivationWithoutDeactivating(t *testing.T) { config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.Deactivation().DeactivatingNotificationDays(0)) // UserTiers @@ -788,21 +789,9 @@ func TestAutomaticDeactivation(t *testing.T) { _, err := r.Reconcile(context.TODO(), req) require.NoError(t, err) - // The user should be deactivating - reloaded := &toolchainv1alpha1.UserSignup{} - err = cl.Get(context.TODO(), types.NamespacedName{Name: userSignupMember1.Name, Namespace: operatorNamespace}, reloaded) - require.NoError(t, err) - require.True(t, states.Deactivating(reloaded)) - - // reconcile again - r, req, cl = prepareReconcile(t, mur.Name, userTier30, mur, reloaded, config) - _, err = r.Reconcile(context.TODO(), req) - require.NoError(t, err) - - // Reload the usersignup, they should now be in a deactivated state - err = cl.Get(context.TODO(), types.NamespacedName{Name: userSignupMember1.Name, Namespace: operatorNamespace}, reloaded) - require.NoError(t, err) - require.True(t, states.Deactivated(reloaded)) + // then + // the usersignup should be in a deactivated state + assertThatUserSignupStateIsDeactivated(t, cl, userSignupMember1.Name, true) } func prepareReconcile(t *testing.T, name string, initObjs ...runtimeclient.Object) (reconcile.Reconciler, reconcile.Request, *commontest.FakeClient) {