(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestWorkspaceQuota(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | |
| 68 | // This first test verifies the behavior of creating and deleting workspaces. |
| 69 | // It also tests multi-group quota stacking and the everyone group. |
| 70 | t.Run("CreateDelete", func(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | |
| 73 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 74 | defer cancel() |
| 75 | maxWorkspaces := 1 |
| 76 | client, _, api, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ |
| 77 | UserWorkspaceQuota: maxWorkspaces, |
| 78 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 79 | Features: license.Features{ |
| 80 | codersdk.FeatureTemplateRBAC: 1, |
| 81 | }, |
| 82 | }, |
| 83 | }) |
| 84 | coderdtest.NewProvisionerDaemon(t, api.AGPL) |
| 85 | |
| 86 | verifyQuota(ctx, t, client, user.OrganizationID.String(), 0, 0) |
| 87 | |
| 88 | // Patch the 'Everyone' group to verify its quota allowance is being accounted for. |
| 89 | _, err := client.PatchGroup(ctx, user.OrganizationID, codersdk.PatchGroupRequest{ |
| 90 | QuotaAllowance: ptr.Ref(1), |
| 91 | }) |
| 92 | require.NoError(t, err) |
| 93 | verifyQuota(ctx, t, client, user.OrganizationID.String(), 0, 1) |
| 94 | |
| 95 | // Add user to two groups, granting them a total budget of 4. |
| 96 | group1, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{ |
| 97 | Name: "test-1", |
| 98 | QuotaAllowance: 1, |
| 99 | }) |
| 100 | require.NoError(t, err) |
| 101 | |
| 102 | group2, err := client.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{ |
| 103 | Name: "test-2", |
| 104 | QuotaAllowance: 2, |
| 105 | }) |
| 106 | require.NoError(t, err) |
| 107 | |
| 108 | _, err = client.PatchGroup(ctx, group1.ID, codersdk.PatchGroupRequest{ |
| 109 | AddUsers: []string{user.UserID.String()}, |
| 110 | }) |
| 111 | require.NoError(t, err) |
| 112 | |
| 113 | _, err = client.PatchGroup(ctx, group2.ID, codersdk.PatchGroupRequest{ |
| 114 | AddUsers: []string{user.UserID.String()}, |
| 115 | }) |
| 116 | require.NoError(t, err) |
| 117 | |
| 118 | verifyQuota(ctx, t, client, user.OrganizationID.String(), 0, 4) |
| 119 | |
| 120 | authToken := uuid.NewString() |
| 121 | version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{ |
| 122 | Parse: echo.ParseComplete, |
nothing calls this directly
no test coverage detected