(t *testing.T)
| 228 | } |
| 229 | |
| 230 | func TestSharingRemove(t *testing.T) { |
| 231 | t.Parallel() |
| 232 | |
| 233 | t.Run("RemoveSharedGroup_Single", func(t *testing.T) { |
| 234 | t.Parallel() |
| 235 | |
| 236 | var ( |
| 237 | client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{ |
| 238 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 239 | Features: license.Features{ |
| 240 | codersdk.FeatureTemplateRBAC: 1, |
| 241 | }, |
| 242 | }, |
| 243 | }) |
| 244 | workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID)) |
| 245 | workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 246 | OwnerID: workspaceOwner.ID, |
| 247 | OrganizationID: orgOwner.OrganizationID, |
| 248 | }).Do().Workspace |
| 249 | _, groupUser1 = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 250 | _, groupUser2 = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 251 | ) |
| 252 | |
| 253 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 254 | |
| 255 | group1, err := createGroupWithMembers(ctx, client, orgOwner.OrganizationID, "group-1", []uuid.UUID{groupUser1.ID, groupUser2.ID}) |
| 256 | require.NoError(t, err) |
| 257 | |
| 258 | group2, err := createGroupWithMembers(ctx, client, orgOwner.OrganizationID, "group-2", []uuid.UUID{groupUser1.ID, groupUser2.ID}) |
| 259 | require.NoError(t, err) |
| 260 | |
| 261 | // Share the workspace with a user to later remove |
| 262 | err = client.UpdateWorkspaceACL(ctx, workspace.ID, codersdk.UpdateWorkspaceACL{ |
| 263 | GroupRoles: map[string]codersdk.WorkspaceRole{ |
| 264 | group1.ID.String(): codersdk.WorkspaceRoleUse, |
| 265 | group2.ID.String(): codersdk.WorkspaceRoleUse, |
| 266 | }, |
| 267 | }) |
| 268 | require.NoError(t, err) |
| 269 | |
| 270 | inv, root := clitest.New(t, |
| 271 | "sharing", |
| 272 | "remove", |
| 273 | workspace.Name, |
| 274 | "--group", group1.Name, |
| 275 | ) |
| 276 | clitest.SetupConfig(t, workspaceOwnerClient, root) |
| 277 | |
| 278 | err = inv.WithContext(ctx).Run() |
| 279 | require.NoError(t, err) |
| 280 | |
| 281 | acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID) |
| 282 | require.NoError(t, err) |
| 283 | |
| 284 | removedGroup1 := true |
| 285 | removedGroup2 := true |
| 286 | for _, group := range acl.Groups { |
| 287 | if group.ID == group1.ID { |
nothing calls this directly
no test coverage detected