(t *testing.T)
| 208 | } |
| 209 | |
| 210 | func TestSharingRemove(t *testing.T) { |
| 211 | t.Parallel() |
| 212 | |
| 213 | t.Run("RemoveSharedUser_Simple", func(t *testing.T) { |
| 214 | t.Parallel() |
| 215 | |
| 216 | var ( |
| 217 | client, db = coderdtest.NewWithDatabase(t, nil) |
| 218 | orgOwner = coderdtest.CreateFirstUser(t, client) |
| 219 | workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID)) |
| 220 | workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 221 | OwnerID: workspaceOwner.ID, |
| 222 | OrganizationID: orgOwner.OrganizationID, |
| 223 | }).Do().Workspace |
| 224 | _, toRemoveUser = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 225 | _, toShareWithUser = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 226 | ) |
| 227 | |
| 228 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 229 | |
| 230 | // Share the workspace with a user to later remove |
| 231 | err := client.UpdateWorkspaceACL(ctx, workspace.ID, codersdk.UpdateWorkspaceACL{ |
| 232 | UserRoles: map[string]codersdk.WorkspaceRole{ |
| 233 | toShareWithUser.ID.String(): codersdk.WorkspaceRoleUse, |
| 234 | toRemoveUser.ID.String(): codersdk.WorkspaceRoleUse, |
| 235 | }, |
| 236 | }) |
| 237 | require.NoError(t, err) |
| 238 | |
| 239 | inv, root := clitest.New(t, |
| 240 | "sharing", |
| 241 | "remove", |
| 242 | workspace.Name, |
| 243 | "--user", toRemoveUser.Username, |
| 244 | ) |
| 245 | clitest.SetupConfig(t, workspaceOwnerClient, root) |
| 246 | |
| 247 | out := new(bytes.Buffer) |
| 248 | inv.Stdout = out |
| 249 | err = inv.WithContext(ctx).Run() |
| 250 | require.NoError(t, err) |
| 251 | |
| 252 | acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID) |
| 253 | require.NoError(t, err) |
| 254 | |
| 255 | removedCorrectUser := true |
| 256 | keptOtherUser := false |
| 257 | for _, user := range acl.Users { |
| 258 | if user.ID == toRemoveUser.ID { |
| 259 | removedCorrectUser = false |
| 260 | } |
| 261 | |
| 262 | if user.ID == toShareWithUser.ID { |
| 263 | keptOtherUser = true |
| 264 | } |
| 265 | } |
| 266 | assert.True(t, removedCorrectUser) |
| 267 | assert.True(t, keptOtherUser) |
nothing calls this directly
no test coverage detected