Path: blob/main/components/gitpod-db/go/dbtest/organization.go
2500 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package dbtest56import (7"context"8"testing"910db "github.com/gitpod-io/gitpod/components/gitpod-db/go"11"github.com/google/uuid"12"github.com/stretchr/testify/require"13"gorm.io/gorm"14)1516func CreateOrganizations(t *testing.T, conn *gorm.DB, entries ...db.Organization) []db.Organization {17t.Helper()1819var records []db.Organization20var ids []string21for _, entry := range entries {22record := db.Organization{23ID: uuid.New(),24Name: "Team1",25Slug: "org-" + uuid.New().String(),26}27if entry.ID != uuid.Nil {28record.ID = entry.ID29}30if entry.Name != "" {31record.Name = entry.Name32}33if entry.Slug != "" {34record.Slug = entry.Slug35}36records = append(records, record)37ids = append(ids, record.ID.String())3839created, err := db.CreateOrganization(context.Background(), conn, record)40require.NoError(t, err)41require.NotNil(t, created)42}4344t.Cleanup(func() {45HardDeleteTeams(t, ids...)46})4748return records49}5051func HardDeleteTeams(t *testing.T, ids ...string) {52if len(ids) > 0 {53require.NoError(t, conn.Where(ids).Delete(&db.Organization{}).Error)54}55}565758