1
0
Fork 1
mirror of https://github.com/hay-kot/homebox.git synced 2024-12-22 23:06:31 +00:00
homebox/backend/internal/repo/main_test.go

53 lines
1,010 B
Go
Raw Normal View History

2022-08-30 02:30:36 +00:00
package repo
import (
"context"
"log"
"math/rand"
"os"
"testing"
"time"
2022-08-30 02:40:54 +00:00
"github.com/hay-kot/content/backend/ent"
2022-08-30 02:30:36 +00:00
_ "github.com/mattn/go-sqlite3"
)
2022-08-31 03:21:18 +00:00
var (
testEntClient *ent.Client
testRepos *AllRepos
testUser *ent.User
testGroup *ent.Group
)
func bootstrap() {
ctx := context.Background()
testGroup, _ = testRepos.Groups.Create(ctx, "test-group")
testUser, _ = testRepos.Users.Create(ctx, UserFactory())
if testGroup == nil || testUser == nil {
log.Fatal("Failed to bootstrap test data")
}
}
2022-08-30 02:30:36 +00:00
func TestMain(m *testing.M) {
rand.Seed(int64(time.Now().Unix()))
client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
if err != nil {
log.Fatalf("failed opening connection to sqlite: %v", err)
}
if err := client.Schema.Create(context.Background()); err != nil {
log.Fatalf("failed creating schema resources: %v", err)
}
testEntClient = client
testRepos = EntAllRepos(testEntClient)
defer client.Close()
2022-08-31 03:21:18 +00:00
bootstrap()
2022-08-30 02:30:36 +00:00
os.Exit(m.Run())
}