Alex Tugarev 9266c7617c
[papi] select active OIDC config for start request – WEB-316 (#17518)
* [papi] select active OIDC config for start request

* rename GetActiveOIDCClientConfigByOrgSlug

* add CreateTeams helper

* [papi] Ensure activation of SSO config deactivates previous one

* applied PR review comment
2023-05-10 19:56:55 +08:00

57 lines
1.2 KiB
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package dbtest
import (
"context"
"testing"
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)
func CreateTeams(t *testing.T, conn *gorm.DB, entries ...db.Team) []db.Team {
t.Helper()
var records []db.Team
var ids []string
for _, entry := range entries {
record := db.Team{
ID: uuid.New(),
Name: "Team1",
Slug: "org-" + uuid.New().String(),
}
if entry.ID != uuid.Nil {
record.ID = entry.ID
}
if entry.Name != "" {
record.Name = entry.Name
}
if entry.Slug != "" {
record.Slug = entry.Slug
}
records = append(records, record)
ids = append(ids, record.ID.String())
created, err := db.CreateTeam(context.Background(), conn, record)
require.NoError(t, err)
require.NotNil(t, created)
}
t.Cleanup(func() {
HardDeleteTeams(t, ids...)
})
return records
}
func HardDeleteTeams(t *testing.T, ids ...string) {
if len(ids) > 0 {
require.NoError(t, conn.Where(ids).Delete(&db.Team{}).Error)
}
}