MCPcopy Index your code
hub / github.com/coder/coder / TestProvisionerJobs

Function TestProvisionerJobs

cli/provisionerjobs_test.go:27–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func 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,

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
TemplateFunction · 0.92
TemplateVersionFunction · 0.92
ProvisionerJobFunction · 0.92
WorkspaceFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92

Tested by

no test coverage detected