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

Function TestReadCustomRoles

coderd/database/querier_test.go:2702–2925  ·  view source on GitHub ↗

TestReadCustomRoles tests the input params returns the correct set of roles.

(t *testing.T)

Source from the content-addressed store, hash-verified

2700
2701// TestReadCustomRoles tests the input params returns the correct set of roles.
2702func TestReadCustomRoles(t *testing.T) {
2703 t.Parallel()
2704
2705 if testing.Short() {
2706 t.SkipNow()
2707 }
2708
2709 sqlDB := testSQLDB(t)
2710 err := migrations.Up(sqlDB)
2711 require.NoError(t, err)
2712
2713 db := database.New(sqlDB)
2714 ctx := testutil.Context(t, testutil.WaitLong)
2715
2716 // Make a few site roles, and a few org roles
2717 orgIDs := make([]uuid.UUID, 3)
2718 for i := range orgIDs {
2719 orgIDs[i] = uuid.New()
2720 }
2721
2722 allRoles := make([]database.CustomRole, 0)
2723 siteRoles := make([]database.CustomRole, 0)
2724 orgRoles := make([]database.CustomRole, 0)
2725 for i := 0; i < 15; i++ {
2726 orgID := uuid.NullUUID{
2727 UUID: orgIDs[i%len(orgIDs)],
2728 Valid: true,
2729 }
2730 if i%4 == 0 {
2731 // Some should be site wide
2732 orgID = uuid.NullUUID{}
2733 }
2734
2735 role, err := db.InsertCustomRole(ctx, database.InsertCustomRoleParams{
2736 Name: fmt.Sprintf("role-%d", i),
2737 OrganizationID: orgID,
2738 })
2739 require.NoError(t, err)
2740 allRoles = append(allRoles, role)
2741 if orgID.Valid {
2742 orgRoles = append(orgRoles, role)
2743 } else {
2744 siteRoles = append(siteRoles, role)
2745 }
2746 }
2747
2748 // normalizedRoleName allows for the simple ElementsMatch to work properly.
2749 normalizedRoleName := func(role database.CustomRole) string {
2750 return role.Name + ":" + role.OrganizationID.UUID.String()
2751 }
2752
2753 roleToLookup := func(role database.CustomRole) database.NameOrganizationPair {
2754 return database.NameOrganizationPair{
2755 Name: role.Name,
2756 OrganizationID: role.OrganizationID.UUID,
2757 }
2758 }
2759

Callers

nothing calls this directly

Calls 13

UpFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
ListFunction · 0.92
SkipNowMethod · 0.80
MatchMethod · 0.80
testSQLDBFunction · 0.70
NewMethod · 0.65
InsertCustomRoleMethod · 0.65
RunMethod · 0.65
CustomRolesMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected