Skip to content

Commit 2b5d7d8

Browse files
committed
chore: add test for adding single group
1 parent 2264c80 commit 2b5d7d8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

enterprise/cli/sharing_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cli_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/coder/coder/v2/cli/clitest"
8+
"github.com/coder/coder/v2/coderd/coderdtest"
9+
"github.com/coder/coder/v2/coderd/database"
10+
"github.com/coder/coder/v2/coderd/database/dbfake"
11+
"github.com/coder/coder/v2/coderd/rbac"
12+
"github.com/coder/coder/v2/codersdk"
13+
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
14+
"github.com/coder/coder/v2/enterprise/coderd/license"
15+
"github.com/coder/coder/v2/testutil"
16+
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
18+
)
19+
20+
func TestSharingShareEnterprise(t *testing.T) {
21+
t.Parallel()
22+
23+
dv := coderdtest.DeploymentValues(t)
24+
dv.Experiments = []string{string(codersdk.ExperimentWorkspaceSharing)}
25+
26+
t.Run("ShareWithGroups_Simple", func(t *testing.T) {
27+
t.Parallel()
28+
29+
var (
30+
client, db, orgOwner = coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
31+
Options: &coderdtest.Options{
32+
DeploymentValues: dv,
33+
},
34+
LicenseOptions: &coderdenttest.LicenseOptions{
35+
Features: license.Features{
36+
codersdk.FeatureTemplateRBAC: 1,
37+
},
38+
},
39+
})
40+
workspaceOwnerClient, workspaceOwner = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID, rbac.ScopedRoleOrgAuditor(orgOwner.OrganizationID))
41+
workspace = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
42+
OwnerID: workspaceOwner.ID,
43+
OrganizationID: orgOwner.OrganizationID,
44+
}).Do().Workspace
45+
_, orgMember = coderdtest.CreateAnotherUser(t, client, orgOwner.OrganizationID)
46+
)
47+
48+
ctx := testutil.Context(t, testutil.WaitMedium)
49+
50+
group, err := client.CreateGroup(ctx, orgOwner.OrganizationID, codersdk.CreateGroupRequest{
51+
Name: "new-group",
52+
DisplayName: "new-group",
53+
})
54+
require.NoError(t, err)
55+
group, err = client.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
56+
AddUsers: []string{orgMember.ID.String()},
57+
})
58+
require.NoError(t, err)
59+
60+
var inv, root = clitest.New(t, "sharing", "share", workspace.Name, "--org", orgOwner.OrganizationID.String(), "--group", group.Name)
61+
clitest.SetupConfig(t, workspaceOwnerClient, root)
62+
63+
out := bytes.NewBuffer(nil)
64+
inv.Stdout = out
65+
err = inv.WithContext(ctx).Run()
66+
require.NoError(t, err)
67+
68+
acl, err := workspaceOwnerClient.WorkspaceACL(inv.Context(), workspace.ID)
69+
require.NoError(t, err)
70+
assert.Len(t, acl.Groups, 1)
71+
assert.Equal(t, acl.Groups[0].Group.ID, group.ID)
72+
assert.Equal(t, acl.Groups[0].Role, codersdk.WorkspaceRoleUse)
73+
})
74+
}

0 commit comments

Comments
 (0)