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

Function TestCreateGroup

enterprise/coderd/groups_test.go:29–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestCreateGroup(t *testing.T) {
30 t.Parallel()
31
32 t.Run("OK", func(t *testing.T) {
33 t.Parallel()
34
35 client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
36 Features: license.Features{
37 codersdk.FeatureTemplateRBAC: 1,
38 },
39 }})
40 userAdminClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
41 ctx := testutil.Context(t, testutil.WaitLong)
42 group, err := userAdminClient.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
43 Name: "hi",
44 AvatarURL: "https://example.com",
45 })
46 require.NoError(t, err)
47 require.Equal(t, "hi", group.Name)
48 require.Equal(t, "https://example.com", group.AvatarURL)
49 require.Empty(t, group.Members)
50 require.Empty(t, group.DisplayName)
51 require.NotEqual(t, uuid.Nil.String(), group.ID.String())
52 })
53
54 t.Run("Audit", func(t *testing.T) {
55 t.Parallel()
56
57 auditor := audit.NewMock()
58 client, user := coderdenttest.New(t, &coderdenttest.Options{
59 AuditLogging: true,
60 Options: &coderdtest.Options{
61 IncludeProvisionerDaemon: true,
62 Auditor: auditor,
63 },
64 LicenseOptions: &coderdenttest.LicenseOptions{
65 Features: license.Features{
66 codersdk.FeatureTemplateRBAC: 1,
67 codersdk.FeatureAuditLog: 1,
68 },
69 },
70 })
71 userAdminClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
72
73 ctx := testutil.Context(t, testutil.WaitLong)
74
75 numLogs := len(auditor.AuditLogs())
76 group, err := userAdminClient.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
77 Name: "hi",
78 })
79 require.NoError(t, err)
80 numLogs++
81 require.Len(t, auditor.AuditLogs(), numLogs)
82 require.True(t, auditor.Contains(t, database.AuditLog{
83 Action: database.AuditActionCreate,
84 ResourceID: group.ID,
85 }))
86 })

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleUserAdminFunction · 0.92
ContextFunction · 0.92
NewMockFunction · 0.92
AsErrorFunction · 0.92
CreateGroupMethod · 0.80
RunMethod · 0.65
EqualMethod · 0.45
EmptyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected