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

Function TestSharingStatus

cli/sharing_test.go:166–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func 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
210func TestSharingRemove(t *testing.T) {
211 t.Parallel()

Callers

nothing calls this directly

Calls 14

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAuditorFunction · 0.92
WorkspaceBuildFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
UpdateWorkspaceACLMethod · 0.80
WithContextMethod · 0.80
RunMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected