diff --git a/controllers/deactivation/deactivation_controller_test.go b/controllers/deactivation/deactivation_controller_test.go index b271aea4e..32f50dfee 100644 --- a/controllers/deactivation/deactivation_controller_test.go +++ b/controllers/deactivation/deactivation_controller_test.go @@ -252,8 +252,29 @@ func TestReconcile(t *testing.T) { userSignupFoobar.Status.ScheduledDeactivationTimestamp = nil r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config) + + // First cause the status update to fail + cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { + switch obj.(type) { + case *toolchainv1alpha1.UserSignup: + return errors.New("mock error") + default: + return cl.Client.Status().Update(ctx, obj) + } + } + // when res, err := r.Reconcile(context.TODO(), req) + + require.Error(t, err) + require.Equal(t, "mock error", err.Error()) + + // Remove the mock update + cl.MockStatusUpdate = nil + + // Attempt the reconcile again + res, err = r.Reconcile(context.TODO(), req) + // then require.NoError(t, err) require.False(t, res.Requeue) @@ -291,8 +312,28 @@ func TestReconcile(t *testing.T) { r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config) + // First cause the status update to fail + cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { + switch obj.(type) { + case *toolchainv1alpha1.UserSignup: + return errors.New("mock error") + default: + return cl.Client.Status().Update(ctx, obj) + } + } + // when res, err := r.Reconcile(context.TODO(), req) + + require.Error(t, err) + require.Equal(t, "mock error", err.Error()) + + // Remove the mock update + cl.MockStatusUpdate = nil + + // Attempt the reconcile again + res, err = r.Reconcile(context.TODO(), req) + // then require.NoError(t, err) require.False(t, res.Requeue)