|
5 | 5 | "context"
|
6 | 6 | "fmt"
|
7 | 7 | "slices"
|
| 8 | + "strings" |
8 | 9 | "testing"
|
9 | 10 |
|
10 | 11 | "github.com/coder/coder/v2/cli/clitest"
|
@@ -67,12 +68,15 @@ func TestSharingShareEnterprise(t *testing.T) {
|
67 | 68 | assert.Len(t, acl.Groups, 1)
|
68 | 69 | assert.Equal(t, acl.Groups[0].Group.ID, group.ID)
|
69 | 70 | assert.Equal(t, acl.Groups[0].Role, codersdk.WorkspaceRoleUse)
|
70 |
| - assert.Contains(t, acl.Groups, codersdk.WorkspaceGroup{ |
71 |
| - Role: codersdk.WorkspaceRoleUse, |
72 |
| - Group: group, |
73 |
| - }) |
74 | 71 |
|
75 |
| - assert.Contains(t, out.String(), group.Name) |
| 72 | + found := false |
| 73 | + for _, line := range strings.Split(out.String(), "\n") { |
| 74 | + found = strings.Contains(line, group.Name) && strings.Contains(line, string(codersdk.WorkspaceRoleAdmin)) |
| 75 | + if found { |
| 76 | + break |
| 77 | + } |
| 78 | + } |
| 79 | + assert.True(t, found, "Expected to find group name %s and role %s in output: %s", group.Name, codersdk.WorkspaceRoleAdmin, out.String()) |
76 | 80 | })
|
77 | 81 |
|
78 | 82 | t.Run("ShareWithGroups_Multiple", func(t *testing.T) {
|
@@ -129,6 +133,56 @@ func TestSharingShareEnterprise(t *testing.T) {
|
129 | 133 | return g.Group.ID == wobbleGroup.ID
|
130 | 134 | }))
|
131 | 135 |
|
| 136 | + t.Run("ShareWithGroups_Role", func(t *testing.T) { |
| 137 | + t.Parallel() |
| 138 | + |
| 139 | + var ( |
| 140 | + client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{ |
| 141 | + Options: &coderdtest.Options{ |
| 142 | + DeploymentValues: dv, |
| 143 | + }, |
| 144 | + LicenseOptions: &coderdenttest.LicenseOptions{ |
| 145 | + Features: license.Features{ |
| 146 | + codersdk.FeatureTemplateRBAC: 1, |
| 147 | + }, |
| 148 | + }, |
| 149 | + }) |
| 150 | + workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID)) |
| 151 | + workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 152 | + OwnerID: workspaceOwner.ID, |
| 153 | + OrganizationID: orgOwner.OrganizationID, |
| 154 | + }).Do().Workspace |
| 155 | + _, orgMember = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 156 | + ) |
| 157 | + |
| 158 | + ctx := testutil.Context(t, testutil.WaitMedium) |
| 159 | + |
| 160 | + group, err := createGroupWithMembers(client, ctx, orgOwner.OrganizationID, "new-group", []uuid.UUID{orgMember.ID}) |
| 161 | + require.NoError(t, err) |
| 162 | + |
| 163 | + inv, root := clitest.New(t, "sharing", "share", workspace.Name, "--org", orgOwner.OrganizationID.String(), "--group", fmt.Sprintf("%s:admin", group.Name)) |
| 164 | + clitest.SetupConfig(t, workspaceOwnerClient, root) |
| 165 | + |
| 166 | + out := bytes.NewBuffer(nil) |
| 167 | + inv.Stdout = out |
| 168 | + err = inv.WithContext(ctx).Run() |
| 169 | + require.NoError(t, err) |
| 170 | + |
| 171 | + acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID) |
| 172 | + require.NoError(t, err) |
| 173 | + assert.Len(t, acl.Groups, 1) |
| 174 | + assert.Equal(t, acl.Groups[0].Group.ID, group.ID) |
| 175 | + assert.Equal(t, acl.Groups[0].Role, codersdk.WorkspaceRoleAdmin) |
| 176 | + |
| 177 | + found := false |
| 178 | + for _, line := range strings.Split(out.String(), "\n") { |
| 179 | + found = strings.Contains(line, group.Name) && strings.Contains(line, string(codersdk.WorkspaceRoleAdmin)) |
| 180 | + if found { |
| 181 | + break |
| 182 | + } |
| 183 | + } |
| 184 | + assert.True(t, found, "Expected to find group name %s and role %s in output: %s", group.Name, codersdk.WorkspaceRoleAdmin, out.String()) |
| 185 | + }) |
132 | 186 | })
|
133 | 187 | }
|
134 | 188 |
|
|
0 commit comments