createTemplateVersion is a helper function to create a version with its dependencies.
(t testing.TB, db database.Store, tpl database.Template, args tvArgs)
| 4467 | |
| 4468 | // createTemplateVersion is a helper function to create a version with its dependencies. |
| 4469 | func createTemplateVersion(t testing.TB, db database.Store, tpl database.Template, args tvArgs) database.TemplateVersion { |
| 4470 | t.Helper() |
| 4471 | version := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 4472 | TemplateID: uuid.NullUUID{ |
| 4473 | UUID: tpl.ID, |
| 4474 | Valid: true, |
| 4475 | }, |
| 4476 | OrganizationID: tpl.OrganizationID, |
| 4477 | CreatedAt: dbtime.Now(), |
| 4478 | UpdatedAt: dbtime.Now(), |
| 4479 | CreatedBy: tpl.CreatedBy, |
| 4480 | }) |
| 4481 | |
| 4482 | latestJob := database.ProvisionerJob{ |
| 4483 | ID: version.JobID, |
| 4484 | Error: sql.NullString{}, |
| 4485 | OrganizationID: tpl.OrganizationID, |
| 4486 | InitiatorID: tpl.CreatedBy, |
| 4487 | Type: database.ProvisionerJobTypeTemplateVersionImport, |
| 4488 | } |
| 4489 | setJobStatus(t, args.Status, &latestJob) |
| 4490 | dbgen.ProvisionerJob(t, db, nil, latestJob) |
| 4491 | if args.CreateWorkspace { |
| 4492 | wrk := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 4493 | ID: args.WorkspaceID, |
| 4494 | CreatedAt: time.Time{}, |
| 4495 | UpdatedAt: time.Time{}, |
| 4496 | OwnerID: tpl.CreatedBy, |
| 4497 | OrganizationID: tpl.OrganizationID, |
| 4498 | TemplateID: tpl.ID, |
| 4499 | }) |
| 4500 | trans := database.WorkspaceTransitionStart |
| 4501 | if args.WorkspaceTransition != "" { |
| 4502 | trans = args.WorkspaceTransition |
| 4503 | } |
| 4504 | latestJob = database.ProvisionerJob{ |
| 4505 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 4506 | InitiatorID: tpl.CreatedBy, |
| 4507 | OrganizationID: tpl.OrganizationID, |
| 4508 | } |
| 4509 | setJobStatus(t, args.Status, &latestJob) |
| 4510 | latestJob = dbgen.ProvisionerJob(t, db, nil, latestJob) |
| 4511 | latestResource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 4512 | JobID: latestJob.ID, |
| 4513 | }) |
| 4514 | dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 4515 | WorkspaceID: wrk.ID, |
| 4516 | TemplateVersionID: version.ID, |
| 4517 | BuildNumber: 1, |
| 4518 | Transition: trans, |
| 4519 | InitiatorID: tpl.CreatedBy, |
| 4520 | JobID: latestJob.ID, |
| 4521 | }) |
| 4522 | for i := 0; i < args.ExtraBuilds; i++ { |
| 4523 | latestJob = database.ProvisionerJob{ |
| 4524 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 4525 | InitiatorID: tpl.CreatedBy, |
| 4526 | OrganizationID: tpl.OrganizationID, |
no test coverage detected