( ctx context.Context, t *testing.T, db database.Store, tmpl database.Template, extTmplVersion templateVersionWithPreset, orgID uuid.UUID, now time.Time, opts *createPrebuiltWorkspaceOpts, )
| 6232 | } |
| 6233 | |
| 6234 | func createPrebuiltWorkspace( |
| 6235 | ctx context.Context, |
| 6236 | t *testing.T, |
| 6237 | db database.Store, |
| 6238 | tmpl database.Template, |
| 6239 | extTmplVersion templateVersionWithPreset, |
| 6240 | orgID uuid.UUID, |
| 6241 | now time.Time, |
| 6242 | opts *createPrebuiltWorkspaceOpts, |
| 6243 | ) { |
| 6244 | // Create job with corresponding resource and agent |
| 6245 | jobError := sql.NullString{} |
| 6246 | if opts != nil && opts.failedJob { |
| 6247 | jobError = sql.NullString{String: "failed", Valid: true} |
| 6248 | } |
| 6249 | job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 6250 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 6251 | OrganizationID: orgID, |
| 6252 | |
| 6253 | CreatedAt: now.Add(-1 * time.Minute), |
| 6254 | Error: jobError, |
| 6255 | }) |
| 6256 | |
| 6257 | // create ready agents |
| 6258 | readyAgents := 0 |
| 6259 | if opts != nil { |
| 6260 | readyAgents = opts.readyAgents |
| 6261 | } |
| 6262 | for i := 0; i < readyAgents; i++ { |
| 6263 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 6264 | JobID: job.ID, |
| 6265 | }) |
| 6266 | agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 6267 | ResourceID: resource.ID, |
| 6268 | }) |
| 6269 | err := db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{ |
| 6270 | ID: agent.ID, |
| 6271 | LifecycleState: database.WorkspaceAgentLifecycleStateReady, |
| 6272 | }) |
| 6273 | require.NoError(t, err) |
| 6274 | } |
| 6275 | |
| 6276 | // create not ready agents |
| 6277 | notReadyAgents := 1 |
| 6278 | if opts != nil { |
| 6279 | notReadyAgents = opts.notReadyAgents |
| 6280 | } |
| 6281 | for i := 0; i < notReadyAgents; i++ { |
| 6282 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 6283 | JobID: job.ID, |
| 6284 | }) |
| 6285 | agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 6286 | ResourceID: resource.ID, |
| 6287 | }) |
| 6288 | err := db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{ |
| 6289 | ID: agent.ID, |
| 6290 | LifecycleState: database.WorkspaceAgentLifecycleStateCreated, |
| 6291 | }) |
no test coverage detected