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

Function TestListCustomRoles

coderd/roles_test.go:19–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestListCustomRoles(t *testing.T) {
20 t.Parallel()
21
22 t.Run("Organizations", func(t *testing.T) {
23 t.Parallel()
24
25 client, db := coderdtest.NewWithDatabase(t, nil)
26 owner := coderdtest.CreateFirstUser(t, client)
27
28 const roleName = "random_role"
29 dbgen.CustomRole(t, db, database.CustomRole{
30 Name: roleName,
31 DisplayName: "Random Role",
32 OrganizationID: uuid.NullUUID{
33 UUID: owner.OrganizationID,
34 Valid: true,
35 },
36 SitePermissions: nil,
37 OrgPermissions: []database.CustomRolePermission{
38 {
39 Negate: false,
40 ResourceType: rbac.ResourceWorkspace.Type,
41 Action: policy.ActionRead,
42 },
43 },
44 UserPermissions: nil,
45 })
46
47 ctx := testutil.Context(t, testutil.WaitShort)
48 roles, err := client.ListOrganizationRoles(ctx, owner.OrganizationID)
49 require.NoError(t, err)
50
51 found := slices.ContainsFunc(roles, func(element codersdk.AssignableRoles) bool {
52 return element.Name == roleName && element.OrganizationID == owner.OrganizationID.String()
53 })
54 require.Truef(t, found, "custom organization role listed")
55 })
56}

Callers

nothing calls this directly

Calls 7

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CustomRoleFunction · 0.92
ContextFunction · 0.92
ListOrganizationRolesMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected