(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestWorkspaceBuild(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | // Only use this context for setup. Use a separate context for subtests! |
| 22 | setupCtx := testutil.Context(t, testutil.WaitMedium) |
| 23 | ownerClient, owner := coderdenttest.New(t, &coderdenttest.Options{ |
| 24 | Options: &coderdtest.Options{ |
| 25 | IncludeProvisionerDaemon: true, |
| 26 | }, |
| 27 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 28 | Features: license.Features{ |
| 29 | codersdk.FeatureAccessControl: 1, |
| 30 | codersdk.FeatureTemplateRBAC: 1, |
| 31 | codersdk.FeatureAdvancedTemplateScheduling: 1, |
| 32 | }, |
| 33 | }, |
| 34 | }) |
| 35 | |
| 36 | // For this test we create two templates: |
| 37 | // tplA will be used to test creation of new workspaces. |
| 38 | // tplB will be used to test builds on existing workspaces. |
| 39 | // This is done to enable parallelization of the sub-tests without them interfering with each other. |
| 40 | // Both templates mandate the promoted version. |
| 41 | // This should be enforced for everyone except template admins. |
| 42 | tplAv1 := coderdtest.CreateTemplateVersion(t, ownerClient, owner.OrganizationID, nil) |
| 43 | tplA := coderdtest.CreateTemplate(t, ownerClient, owner.OrganizationID, tplAv1.ID) |
| 44 | coderdtest.AwaitTemplateVersionJobCompleted(t, ownerClient, tplAv1.ID) |
| 45 | require.Equal(t, tplAv1.ID, tplA.ActiveVersionID) |
| 46 | tplA = coderdtest.UpdateTemplateMeta(t, ownerClient, tplA.ID, codersdk.UpdateTemplateMeta{ |
| 47 | RequireActiveVersion: ptr.Ref(true), |
| 48 | }) |
| 49 | require.True(t, tplA.RequireActiveVersion) |
| 50 | tplAv2 := coderdtest.CreateTemplateVersion(t, ownerClient, owner.OrganizationID, nil, func(ctvr *codersdk.CreateTemplateVersionRequest) { |
| 51 | ctvr.TemplateID = tplA.ID |
| 52 | }) |
| 53 | coderdtest.AwaitTemplateVersionJobCompleted(t, ownerClient, tplAv2.ID) |
| 54 | coderdtest.UpdateActiveTemplateVersion(t, ownerClient, tplA.ID, tplAv2.ID) |
| 55 | |
| 56 | tplBv1 := coderdtest.CreateTemplateVersion(t, ownerClient, owner.OrganizationID, nil) |
| 57 | tplB := coderdtest.CreateTemplate(t, ownerClient, owner.OrganizationID, tplBv1.ID) |
| 58 | coderdtest.AwaitTemplateVersionJobCompleted(t, ownerClient, tplBv1.ID) |
| 59 | require.Equal(t, tplBv1.ID, tplB.ActiveVersionID) |
| 60 | tplB = coderdtest.UpdateTemplateMeta(t, ownerClient, tplB.ID, codersdk.UpdateTemplateMeta{ |
| 61 | RequireActiveVersion: ptr.Ref(true), |
| 62 | }) |
| 63 | require.True(t, tplB.RequireActiveVersion) |
| 64 | |
| 65 | templateAdminClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 66 | templateACLAdminClient, templateACLAdmin := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 67 | templateGroupACLAdminClient, templateGroupACLAdmin := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 68 | memberClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 69 | |
| 70 | // Create a group so we can also test group template admin ownership. |
| 71 | // Add the user who gains template admin via group membership. |
| 72 | group := coderdtest.CreateGroup(t, ownerClient, owner.OrganizationID, "test", templateGroupACLAdmin) |
| 73 | |
| 74 | // Update the template for both users and groups. |
| 75 | //nolint:gocritic // test setup |
nothing calls this directly
no test coverage detected