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

Function TestSharingStatus

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

Source from the content-addressed store, hash-verified

176}
177
178func TestSharingStatus(t *testing.T) {
179 t.Parallel()
180
181 t.Run("ListSharedUsers", func(t *testing.T) {
182 t.Parallel()
183
184 var (
185 client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
186 LicenseOptions: &coderdenttest.LicenseOptions{
187 Features: license.Features{
188 codersdk.FeatureTemplateRBAC: 1,
189 },
190 },
191 })
192 workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID))
193 workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
194 OwnerID: workspaceOwner.ID,
195 OrganizationID: orgOwner.OrganizationID,
196 }).Do().Workspace
197 _, orgMember = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID)
198 ctx = testutil.Context(t, testutil.WaitMedium)
199 )
200
201 group, err := createGroupWithMembers(ctx, client, orgOwner.OrganizationID, "new-group", []uuid.UUID{orgMember.ID})
202 require.NoError(t, err)
203
204 err = client.UpdateWorkspaceACL(ctx, workspace.ID, codersdk.UpdateWorkspaceACL{
205 GroupRoles: map[string]codersdk.WorkspaceRole{
206 group.ID.String(): codersdk.WorkspaceRoleUse,
207 },
208 })
209 require.NoError(t, err)
210
211 inv, root := clitest.New(t, "sharing", "status", workspace.Name)
212 clitest.SetupConfig(t, workspaceOwnerClient, root)
213
214 out := new(bytes.Buffer)
215 inv.Stdout = out
216 err = inv.WithContext(ctx).Run()
217 require.NoError(t, err)
218
219 found := false
220 for _, line := range strings.Split(out.String(), "\n") {
221 if strings.Contains(line, orgMember.Username) && strings.Contains(line, string(codersdk.WorkspaceRoleUse)) && strings.Contains(line, group.Name) {
222 found = true
223 break
224 }
225 }
226 assert.True(t, found, "expected to find username %s with role %s in the output: %s", orgMember.Username, codersdk.WorkspaceRoleUse, out.String())
227 })
228}
229
230func TestSharingRemove(t *testing.T) {
231 t.Parallel()

Callers

nothing calls this directly

Calls 14

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
RunMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected