(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestProvisionerJobs(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | t.Run("Cancel", func(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | |
| 33 | db, ps := dbtestutil.NewDB(t) |
| 34 | client, _, coderdAPI := coderdtest.NewWithAPI(t, &coderdtest.Options{ |
| 35 | IncludeProvisionerDaemon: false, |
| 36 | Database: db, |
| 37 | Pubsub: ps, |
| 38 | }) |
| 39 | owner := coderdtest.CreateFirstUser(t, client) |
| 40 | templateAdminClient, templateAdmin := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID)) |
| 41 | memberClient, member := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) |
| 42 | |
| 43 | // These CLI tests are related to provisioner job CRUD operations and as such |
| 44 | // do not require the overhead of starting a provisioner. Other provisioner job |
| 45 | // functionalities (acquisition etc.) are tested elsewhere. |
| 46 | template := dbgen.Template(t, db, database.Template{ |
| 47 | OrganizationID: owner.OrganizationID, |
| 48 | CreatedBy: owner.UserID, |
| 49 | AllowUserCancelWorkspaceJobs: true, |
| 50 | }) |
| 51 | version := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 52 | OrganizationID: owner.OrganizationID, |
| 53 | CreatedBy: owner.UserID, |
| 54 | TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true}, |
| 55 | }) |
| 56 | // Test helper to create a provisioner job of a given type with a given input. |
| 57 | prepareJob := func(t *testing.T, jobType database.ProvisionerJobType, input json.RawMessage) database.ProvisionerJob { |
| 58 | t.Helper() |
| 59 | return dbgen.ProvisionerJob(t, db, coderdAPI.Pubsub, database.ProvisionerJob{ |
| 60 | InitiatorID: member.ID, |
| 61 | Input: input, |
| 62 | Type: jobType, |
| 63 | StartedAt: sql.NullTime{Time: coderdAPI.Clock.Now().Add(-time.Minute), Valid: true}, |
| 64 | Tags: database.StringMap{provisionersdk.TagOwner: "", provisionersdk.TagScope: provisionersdk.ScopeOrganization, "foo": uuid.NewString()}, |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | // Test helper to create a workspace build job with a predefined input. |
| 69 | prepareWorkspaceBuildJob := func(t *testing.T) database.ProvisionerJob { |
| 70 | t.Helper() |
| 71 | var ( |
| 72 | wbID = uuid.New() |
| 73 | input, _ = json.Marshal(map[string]string{"workspace_build_id": wbID.String()}) |
| 74 | job = prepareJob(t, database.ProvisionerJobTypeWorkspaceBuild, input) |
| 75 | w = dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 76 | OrganizationID: owner.OrganizationID, |
| 77 | OwnerID: member.ID, |
| 78 | TemplateID: template.ID, |
| 79 | }) |
| 80 | _ = dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 81 | ID: wbID, |
| 82 | InitiatorID: member.ID, |
| 83 | WorkspaceID: w.ID, |
| 84 | TemplateVersionID: version.ID, |
nothing calls this directly
no test coverage detected