Skip to content

Commit a91b915

Browse files
refactor: minor refactoring
1 parent 3764adb commit a91b915

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

enterprise/coderd/prebuilds/claim_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type storeSpy struct {
3737
claimParams *atomic.Pointer[database.ClaimPrebuiltWorkspaceParams]
3838
claimedWorkspace *atomic.Pointer[database.ClaimPrebuiltWorkspaceRow]
3939

40+
// if claimingErr is not nil - error will be returned when ClaimPrebuiltWorkspace is called
4041
claimingErr error
4142
}
4243

@@ -93,7 +94,8 @@ func TestClaimPrebuild(t *testing.T) {
9394
cases := map[string]struct {
9495
expectPrebuildClaimed bool
9596
markPrebuildsClaimable bool
96-
storeError error // should be set only for errorStoreType
97+
// if claimingErr is not nil - error will be returned when ClaimPrebuiltWorkspace is called
98+
claimingErr error
9799
}{
98100
"no eligible prebuilds to claim": {
99101
expectPrebuildClaimed: false,
@@ -107,12 +109,12 @@ func TestClaimPrebuild(t *testing.T) {
107109
"no claimable prebuilt workspaces error is returned": {
108110
expectPrebuildClaimed: false,
109111
markPrebuildsClaimable: true,
110-
storeError: agplprebuilds.ErrNoClaimablePrebuiltWorkspaces,
112+
claimingErr: agplprebuilds.ErrNoClaimablePrebuiltWorkspaces,
111113
},
112114
"unexpected claiming error is returned": {
113115
expectPrebuildClaimed: false,
114116
markPrebuildsClaimable: true,
115-
storeError: unexpectedClaimingError,
117+
claimingErr: unexpectedClaimingError,
116118
},
117119
}
118120

@@ -126,7 +128,7 @@ func TestClaimPrebuild(t *testing.T) {
126128
ctx := testutil.Context(t, testutil.WaitSuperLong)
127129
db, pubsub := dbtestutil.NewDB(t)
128130

129-
spy := newStoreSpy(db, tc.storeError)
131+
spy := newStoreSpy(db, tc.claimingErr)
130132
expectedPrebuildsCount := desiredInstances * presetCount
131133

132134
logger := testutil.Logger(t)
@@ -223,7 +225,7 @@ func TestClaimPrebuild(t *testing.T) {
223225
})
224226

225227
switch {
226-
case tc.storeError != nil && errors.Is(tc.storeError, agplprebuilds.ErrNoClaimablePrebuiltWorkspaces):
228+
case tc.claimingErr != nil && errors.Is(tc.claimingErr, agplprebuilds.ErrNoClaimablePrebuiltWorkspaces):
227229
require.NoError(t, err)
228230
coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, userWorkspace.LatestBuild.ID)
229231

@@ -233,7 +235,7 @@ func TestClaimPrebuild(t *testing.T) {
233235
require.Equal(t, expectedPrebuildsCount, len(currentPrebuilds))
234236
return
235237

236-
case tc.storeError != nil && errors.Is(tc.storeError, unexpectedClaimingError):
238+
case tc.claimingErr != nil && errors.Is(tc.claimingErr, unexpectedClaimingError):
237239
// Then: unexpected error happened and was propagated all the way to the caller
238240
require.Error(t, err)
239241
require.ErrorContains(t, err, unexpectedClaimingError.Error())
@@ -245,12 +247,12 @@ func TestClaimPrebuild(t *testing.T) {
245247
return
246248

247249
default:
248-
// tc.storeType == spyStoreType scenario
250+
// tc.claimingErr is nil scenario
249251
require.NoError(t, err)
250252
coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, userWorkspace.LatestBuild.ID)
251253
}
252254

253-
// at this point we know that wrappedStore has *storeSpy type
255+
// at this point we know that tc.claimingErr is nil
254256

255257
// Then: a prebuild should have been claimed.
256258
require.EqualValues(t, spy.claims.Load(), 1)

0 commit comments

Comments
 (0)