Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3764adb

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

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

enterprise/coderd/prebuilds/claim_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ func TestClaimPrebuild(t *testing.T) {
126126
ctx := testutil.Context(t, testutil.WaitSuperLong)
127127
db, pubsub := dbtestutil.NewDB(t)
128128

129-
wrappedStore := newStoreSpy(db, tc.storeError)
129+
spy := newStoreSpy(db, tc.storeError)
130130
expectedPrebuildsCount := desiredInstances * presetCount
131131

132132
logger := testutil.Logger(t)
133133
client, _, api, owner := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
134134
Options: &coderdtest.Options{
135135
IncludeProvisionerDaemon: true,
136-
Database: wrappedStore,
136+
Database: spy,
137137
Pubsub: pubsub,
138138
},
139139

140140
EntitlementsUpdateInterval: time.Second,
141141
})
142142

143-
reconciler := prebuilds.NewStoreReconciler(wrappedStore, pubsub, codersdk.PrebuildsConfig{}, logger, quartz.NewMock(t), prometheus.NewRegistry())
144-
var claimer agplprebuilds.Claimer = prebuilds.NewEnterpriseClaimer(wrappedStore)
143+
reconciler := prebuilds.NewStoreReconciler(spy, pubsub, codersdk.PrebuildsConfig{}, logger, quartz.NewMock(t), prometheus.NewRegistry())
144+
var claimer agplprebuilds.Claimer = prebuilds.NewEnterpriseClaimer(spy)
145145
api.AGPL.PrebuildsClaimer.Store(&claimer)
146146

147147
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, templateWithAgentAndPresetsWithPrebuilds(desiredInstances))
@@ -154,7 +154,7 @@ func TestClaimPrebuild(t *testing.T) {
154154
userClient, user := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleMember())
155155

156156
// Given: the reconciliation state is snapshot.
157-
state, err := reconciler.SnapshotState(ctx, wrappedStore)
157+
state, err := reconciler.SnapshotState(ctx, spy)
158158
require.NoError(t, err)
159159
require.Len(t, state.Presets, presetCount)
160160

@@ -173,7 +173,7 @@ func TestClaimPrebuild(t *testing.T) {
173173
// Given: a set of running, eligible prebuilds eventually starts up.
174174
runningPrebuilds := make(map[uuid.UUID]database.GetRunningPrebuiltWorkspacesRow, desiredInstances*presetCount)
175175
require.Eventually(t, func() bool {
176-
rows, err := wrappedStore.GetRunningPrebuiltWorkspaces(ctx)
176+
rows, err := spy.GetRunningPrebuiltWorkspaces(ctx)
177177
if err != nil {
178178
return false
179179
}
@@ -228,7 +228,7 @@ func TestClaimPrebuild(t *testing.T) {
228228
coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, userWorkspace.LatestBuild.ID)
229229

230230
// Then: the number of running prebuilds hasn't changed because claiming prebuild is failed and we fallback to creating new workspace.
231-
currentPrebuilds, err := wrappedStore.GetRunningPrebuiltWorkspaces(ctx)
231+
currentPrebuilds, err := spy.GetRunningPrebuiltWorkspaces(ctx)
232232
require.NoError(t, err)
233233
require.Equal(t, expectedPrebuildsCount, len(currentPrebuilds))
234234
return
@@ -239,7 +239,7 @@ func TestClaimPrebuild(t *testing.T) {
239239
require.ErrorContains(t, err, unexpectedClaimingError.Error())
240240

241241
// Then: the number of running prebuilds hasn't changed because claiming prebuild is failed.
242-
currentPrebuilds, err := wrappedStore.GetRunningPrebuiltWorkspaces(ctx)
242+
currentPrebuilds, err := spy.GetRunningPrebuiltWorkspaces(ctx)
243243
require.NoError(t, err)
244244
require.Equal(t, expectedPrebuildsCount, len(currentPrebuilds))
245245
return
@@ -251,7 +251,6 @@ func TestClaimPrebuild(t *testing.T) {
251251
}
252252

253253
// at this point we know that wrappedStore has *storeSpy type
254-
spy := wrappedStore
255254

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

0 commit comments

Comments
 (0)