(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestSharingShare(t *testing.T) { |
| 27 | t.Parallel() |
| 28 | |
| 29 | t.Run("ShareWithGroups_Simple", func(t *testing.T) { |
| 30 | t.Parallel() |
| 31 | |
| 32 | var ( |
| 33 | client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{ |
| 34 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 35 | Features: license.Features{ |
| 36 | codersdk.FeatureTemplateRBAC: 1, |
| 37 | }, |
| 38 | }, |
| 39 | }) |
| 40 | workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID)) |
| 41 | workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 42 | OwnerID: workspaceOwner.ID, |
| 43 | OrganizationID: orgOwner.OrganizationID, |
| 44 | }).Do().Workspace |
| 45 | _, orgMember = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 46 | ) |
| 47 | |
| 48 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 49 | |
| 50 | group, err := createGroupWithMembers(ctx, client, orgOwner.OrganizationID, "new-group", []uuid.UUID{orgMember.ID}) |
| 51 | require.NoError(t, err) |
| 52 | |
| 53 | inv, root := clitest.New(t, "sharing", "share", workspace.Name, "--group", group.Name) |
| 54 | clitest.SetupConfig(t, workspaceOwnerClient, root) |
| 55 | |
| 56 | out := new(bytes.Buffer) |
| 57 | inv.Stdout = out |
| 58 | err = inv.WithContext(ctx).Run() |
| 59 | require.NoError(t, err) |
| 60 | |
| 61 | acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID) |
| 62 | require.NoError(t, err) |
| 63 | assert.Len(t, acl.Groups, 1) |
| 64 | assert.Equal(t, acl.Groups[0].Group.ID, group.ID) |
| 65 | assert.Equal(t, acl.Groups[0].Role, codersdk.WorkspaceRoleUse) |
| 66 | |
| 67 | found := false |
| 68 | for _, line := range strings.Split(out.String(), "\n") { |
| 69 | found = strings.Contains(line, group.Name) && strings.Contains(line, string(codersdk.WorkspaceRoleUse)) |
| 70 | if found { |
| 71 | break |
| 72 | } |
| 73 | } |
| 74 | assert.True(t, found, "Expected to find group name %s and role %s in output: %s", group.Name, codersdk.WorkspaceRoleUse, out.String()) |
| 75 | }) |
| 76 | |
| 77 | t.Run("ShareWithGroups_Multiple", func(t *testing.T) { |
| 78 | t.Parallel() |
| 79 | |
| 80 | var ( |
| 81 | client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{ |
| 82 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 83 | Features: license.Features{ |
nothing calls this directly
no test coverage detected