Files
coder/coderd/rbac/rolestore/rolestore_test.go
Steven Masley 5ccf5084e8 chore: create type for unique role names (#13506)
* chore: create type for unique role names

Using `string` was confusing when something should be combined with
org context, and when not to. Naming this new name, "RoleIdentifier"
2024-06-11 08:55:28 -05:00

42 lines
1.0 KiB
Go

package rolestore_test
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbgen"
"github.com/coder/coder/v2/coderd/database/dbmem"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/rbac/rolestore"
"github.com/coder/coder/v2/testutil"
)
func TestExpandCustomRoleRoles(t *testing.T) {
t.Parallel()
db := dbmem.New()
org := dbgen.Organization(t, db, database.Organization{})
const roleName = "test-role"
dbgen.CustomRole(t, db, database.CustomRole{
Name: roleName,
DisplayName: "",
SitePermissions: nil,
OrgPermissions: nil,
UserPermissions: nil,
OrganizationID: uuid.NullUUID{
UUID: org.ID,
Valid: true,
},
})
ctx := testutil.Context(t, testutil.WaitShort)
roles, err := rolestore.Expand(ctx, db, []rbac.RoleIdentifier{{Name: roleName, OrganizationID: org.ID}})
require.NoError(t, err)
require.Len(t, roles, 1, "role found")
}