Skip to content

Commit

Permalink
even more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sbryzak committed May 1, 2024
1 parent e729c5a commit 193ac5b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions controllers/deactivation/deactivation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 267 in controllers/deactivation/deactivation_controller_test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint

ineffectual assignment to res (ineffassign)

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)
Expand Down Expand Up @@ -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)

Check failure on line 326 in controllers/deactivation/deactivation_controller_test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint

ineffectual assignment to res (ineffassign)

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)
Expand Down

0 comments on commit 193ac5b

Please sign in to comment.