MCPcopy Create free account
hub / github.com/coder/coder / setupTestDBWorkspaceAgent

Function setupTestDBWorkspaceAgent

enterprise/coderd/prebuilds/reconcile_test.go:3290–3311  ·  view source on GitHub ↗

nolint:revive // It's a control flag, but this is a test.

(t *testing.T, db database.Store, workspaceID uuid.UUID, eligible bool)

Source from the content-addressed store, hash-verified

3288
3289// nolint:revive // It's a control flag, but this is a test.
3290func setupTestDBWorkspaceAgent(t *testing.T, db database.Store, workspaceID uuid.UUID, eligible bool) database.WorkspaceAgent {
3291 build, err := db.GetLatestWorkspaceBuildByWorkspaceID(t.Context(), workspaceID)
3292 require.NoError(t, err)
3293
3294 res := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{JobID: build.JobID})
3295 agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{
3296 ResourceID: res.ID,
3297 })
3298
3299 // A prebuilt workspace is considered eligible when its agent is in a "ready" lifecycle state.
3300 // i.e. connected to the control plane and all startup scripts have run.
3301 if eligible {
3302 require.NoError(t, db.UpdateWorkspaceAgentLifecycleStateByID(t.Context(), database.UpdateWorkspaceAgentLifecycleStateByIDParams{
3303 ID: agent.ID,
3304 LifecycleState: database.WorkspaceAgentLifecycleStateReady,
3305 StartedAt: sql.NullTime{Time: dbtime.Now().Add(-time.Minute), Valid: true},
3306 ReadyAt: sql.NullTime{Time: dbtime.Now(), Valid: true},
3307 }))
3308 }
3309
3310 return agent
3311}
3312
3313// setupTestDBAntagonists creates test antagonists that should not influence running prebuild workspace tests.
3314// 1. A stopped prebuilt workspace (STOP then START transitions, owned by

Calls 7

WorkspaceResourceFunction · 0.92
WorkspaceAgentFunction · 0.92
NowFunction · 0.92
ContextMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected