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

Function TestSharingShare

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

Source from the content-addressed store, hash-verified

19)
20
21func TestSharingShare(t *testing.T) {
22 t.Parallel()
23
24 t.Run("ShareWithUsers_Simple", func(t *testing.T) {
25 t.Parallel()
26
27 var (
28 client, db = coderdtest.NewWithDatabase(t, nil)
29 orgOwner = coderdtest.CreateFirstUser(t, client)
30 workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID))
31 workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
32 OwnerID: workspaceOwner.ID,
33 OrganizationID: orgOwner.OrganizationID,
34 }).Do().Workspace
35 _, toShareWithUser = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID)
36 )
37
38 ctx := testutil.Context(t, testutil.WaitMedium)
39 inv, root := clitest.New(t, "sharing", "add", workspace.Name, "--user", toShareWithUser.Username)
40 clitest.SetupConfig(t, workspaceOwnerClient, root)
41
42 out := new(bytes.Buffer)
43 inv.Stdout = out
44 err := inv.WithContext(ctx).Run()
45 require.NoError(t, err)
46
47 acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID)
48 require.NoError(t, err)
49 assert.Contains(t, acl.Users, codersdk.WorkspaceUser{
50 MinimalUser: codersdk.MinimalUser{
51 ID: toShareWithUser.ID,
52 Username: toShareWithUser.Username,
53 Name: toShareWithUser.Name,
54 AvatarURL: toShareWithUser.AvatarURL,
55 },
56 Role: codersdk.WorkspaceRole("use"),
57 })
58
59 assert.Contains(t, out.String(), toShareWithUser.Username)
60 assert.Contains(t, out.String(), codersdk.WorkspaceRoleUse)
61 })
62
63 t.Run("ShareWithUsers_Multiple", func(t *testing.T) {
64 t.Parallel()
65
66 var (
67 client, db = coderdtest.NewWithDatabase(t, nil)
68 orgOwner = coderdtest.CreateFirstUser(t, client)
69
70 workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID))
71 workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
72 OwnerID: workspaceOwner.ID,
73 OrganizationID: orgOwner.OrganizationID,
74 }).Do().Workspace
75
76 _, toShareWithUser1 = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID)
77 _, toShareWithUser2 = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID)
78 )

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAuditorFunction · 0.92
WorkspaceBuildFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
WorkspaceRoleTypeAlias · 0.92
WithContextMethod · 0.80
WorkspaceACLMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected