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

Function TestSharingRemove

enterprise/cli/sharing_test.go:230–368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

228}
229
230func 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 {

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAuditorFunction · 0.92
WorkspaceBuildFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
createGroupWithMembersFunction · 0.85
UpdateWorkspaceACLMethod · 0.80
WithContextMethod · 0.80
WorkspaceACLMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected