(t *testing.T)
| 164 | } |
| 165 | |
| 166 | func TestSharingStatus(t *testing.T) { |
| 167 | t.Parallel() |
| 168 | |
| 169 | t.Run("ListSharedUsers", func(t *testing.T) { |
| 170 | t.Parallel() |
| 171 | |
| 172 | var ( |
| 173 | client, db = coderdtest.NewWithDatabase(t, nil) |
| 174 | orgOwner = coderdtest.CreateFirstUser(t, client) |
| 175 | workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID)) |
| 176 | workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 177 | OwnerID: workspaceOwner.ID, |
| 178 | OrganizationID: orgOwner.OrganizationID, |
| 179 | }).Do().Workspace |
| 180 | _, toShareWithUser = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID) |
| 181 | ctx = testutil.Context(t, testutil.WaitMedium) |
| 182 | ) |
| 183 | |
| 184 | err := client.UpdateWorkspaceACL(ctx, workspace.ID, codersdk.UpdateWorkspaceACL{ |
| 185 | UserRoles: map[string]codersdk.WorkspaceRole{ |
| 186 | toShareWithUser.ID.String(): codersdk.WorkspaceRoleUse, |
| 187 | }, |
| 188 | }) |
| 189 | require.NoError(t, err) |
| 190 | |
| 191 | inv, root := clitest.New(t, "sharing", "status", workspace.Name) |
| 192 | clitest.SetupConfig(t, workspaceOwnerClient, root) |
| 193 | |
| 194 | out := new(bytes.Buffer) |
| 195 | inv.Stdout = out |
| 196 | err = inv.WithContext(ctx).Run() |
| 197 | require.NoError(t, err) |
| 198 | |
| 199 | found := false |
| 200 | for _, line := range strings.Split(out.String(), "\n") { |
| 201 | if strings.Contains(line, toShareWithUser.Username) && strings.Contains(line, string(codersdk.WorkspaceRoleUse)) { |
| 202 | found = true |
| 203 | break |
| 204 | } |
| 205 | } |
| 206 | assert.True(t, found, "expected to find username %s with role %s in the output: %s", toShareWithUser.Username, codersdk.WorkspaceRoleUse, out.String()) |
| 207 | }) |
| 208 | } |
| 209 | |
| 210 | func TestSharingRemove(t *testing.T) { |
| 211 | t.Parallel() |
nothing calls this directly
no test coverage detected