@@ -37,6 +37,7 @@ type storeSpy struct {
37
37
claimParams * atomic.Pointer [database.ClaimPrebuiltWorkspaceParams ]
38
38
claimedWorkspace * atomic.Pointer [database.ClaimPrebuiltWorkspaceRow ]
39
39
40
+ // if claimingErr is not nil - error will be returned when ClaimPrebuiltWorkspace is called
40
41
claimingErr error
41
42
}
42
43
@@ -93,7 +94,8 @@ func TestClaimPrebuild(t *testing.T) {
93
94
cases := map [string ]struct {
94
95
expectPrebuildClaimed bool
95
96
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
97
99
}{
98
100
"no eligible prebuilds to claim" : {
99
101
expectPrebuildClaimed : false ,
@@ -107,12 +109,12 @@ func TestClaimPrebuild(t *testing.T) {
107
109
"no claimable prebuilt workspaces error is returned" : {
108
110
expectPrebuildClaimed : false ,
109
111
markPrebuildsClaimable : true ,
110
- storeError : agplprebuilds .ErrNoClaimablePrebuiltWorkspaces ,
112
+ claimingErr : agplprebuilds .ErrNoClaimablePrebuiltWorkspaces ,
111
113
},
112
114
"unexpected claiming error is returned" : {
113
115
expectPrebuildClaimed : false ,
114
116
markPrebuildsClaimable : true ,
115
- storeError : unexpectedClaimingError ,
117
+ claimingErr : unexpectedClaimingError ,
116
118
},
117
119
}
118
120
@@ -126,7 +128,7 @@ func TestClaimPrebuild(t *testing.T) {
126
128
ctx := testutil .Context (t , testutil .WaitSuperLong )
127
129
db , pubsub := dbtestutil .NewDB (t )
128
130
129
- spy := newStoreSpy (db , tc .storeError )
131
+ spy := newStoreSpy (db , tc .claimingErr )
130
132
expectedPrebuildsCount := desiredInstances * presetCount
131
133
132
134
logger := testutil .Logger (t )
@@ -223,7 +225,7 @@ func TestClaimPrebuild(t *testing.T) {
223
225
})
224
226
225
227
switch {
226
- case tc .storeError != nil && errors .Is (tc .storeError , agplprebuilds .ErrNoClaimablePrebuiltWorkspaces ):
228
+ case tc .claimingErr != nil && errors .Is (tc .claimingErr , agplprebuilds .ErrNoClaimablePrebuiltWorkspaces ):
227
229
require .NoError (t , err )
228
230
coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , userWorkspace .LatestBuild .ID )
229
231
@@ -233,7 +235,7 @@ func TestClaimPrebuild(t *testing.T) {
233
235
require .Equal (t , expectedPrebuildsCount , len (currentPrebuilds ))
234
236
return
235
237
236
- case tc .storeError != nil && errors .Is (tc .storeError , unexpectedClaimingError ):
238
+ case tc .claimingErr != nil && errors .Is (tc .claimingErr , unexpectedClaimingError ):
237
239
// Then: unexpected error happened and was propagated all the way to the caller
238
240
require .Error (t , err )
239
241
require .ErrorContains (t , err , unexpectedClaimingError .Error ())
@@ -245,12 +247,12 @@ func TestClaimPrebuild(t *testing.T) {
245
247
return
246
248
247
249
default :
248
- // tc.storeType == spyStoreType scenario
250
+ // tc.claimingErr is nil scenario
249
251
require .NoError (t , err )
250
252
coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , userWorkspace .LatestBuild .ID )
251
253
}
252
254
253
- // at this point we know that wrappedStore has *storeSpy type
255
+ // at this point we know that tc.claimingErr is nil
254
256
255
257
// Then: a prebuild should have been claimed.
256
258
require .EqualValues (t , spy .claims .Load (), 1 )
0 commit comments