Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/go/dbtest/organization.go
2500 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package dbtest
6
7
import (
8
"context"
9
"testing"
10
11
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
12
"github.com/google/uuid"
13
"github.com/stretchr/testify/require"
14
"gorm.io/gorm"
15
)
16
17
func CreateOrganizations(t *testing.T, conn *gorm.DB, entries ...db.Organization) []db.Organization {
18
t.Helper()
19
20
var records []db.Organization
21
var ids []string
22
for _, entry := range entries {
23
record := db.Organization{
24
ID: uuid.New(),
25
Name: "Team1",
26
Slug: "org-" + uuid.New().String(),
27
}
28
if entry.ID != uuid.Nil {
29
record.ID = entry.ID
30
}
31
if entry.Name != "" {
32
record.Name = entry.Name
33
}
34
if entry.Slug != "" {
35
record.Slug = entry.Slug
36
}
37
records = append(records, record)
38
ids = append(ids, record.ID.String())
39
40
created, err := db.CreateOrganization(context.Background(), conn, record)
41
require.NoError(t, err)
42
require.NotNil(t, created)
43
}
44
45
t.Cleanup(func() {
46
HardDeleteTeams(t, ids...)
47
})
48
49
return records
50
}
51
52
func HardDeleteTeams(t *testing.T, ids ...string) {
53
if len(ids) > 0 {
54
require.NoError(t, conn.Where(ids).Delete(&db.Organization{}).Error)
55
}
56
}
57
58