forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroles_test.go
More file actions
56 lines (47 loc) · 1.48 KB
/
Copy pathroles_test.go
File metadata and controls
56 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package coderd_test
import (
"slices"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbgen"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/rbac/policy"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/testutil"
)
func TestListCustomRoles(t *testing.T) {
t.Parallel()
t.Run("Organizations", func(t *testing.T) {
t.Parallel()
client, db := coderdtest.NewWithDatabase(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
const roleName = "random_role"
dbgen.CustomRole(t, db, database.CustomRole{
Name: roleName,
DisplayName: "Random Role",
OrganizationID: uuid.NullUUID{
UUID: owner.OrganizationID,
Valid: true,
},
SitePermissions: nil,
OrgPermissions: []database.CustomRolePermission{
{
Negate: false,
ResourceType: rbac.ResourceWorkspace.Type,
Action: policy.ActionRead,
},
},
UserPermissions: nil,
})
ctx := testutil.Context(t, testutil.WaitShort)
roles, err := client.ListOrganizationRoles(ctx, owner.OrganizationID)
require.NoError(t, err)
found := slices.ContainsFunc(roles, func(element codersdk.AssignableRoles) bool {
return element.Name == roleName && element.OrganizationID == owner.OrganizationID.String()
})
require.Truef(t, found, "custom organization role listed")
})
}