mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 13:06:32 +00:00
2867a05c92
* use new httpkit runner * refactor out last httpkit changes * fix timeout defaults * fix wrong time input - closes #819
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/core/services/reporting/eventbus"
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
|
"github.com/hay-kot/homebox/backend/pkgs/faker"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
var (
|
|
fk = faker.NewFaker()
|
|
tbus = eventbus.New()
|
|
|
|
tClient *ent.Client
|
|
tRepos *AllRepos
|
|
tUser UserOut
|
|
tGroup Group
|
|
)
|
|
|
|
func bootstrap() {
|
|
var (
|
|
err error
|
|
ctx = context.Background()
|
|
)
|
|
|
|
tGroup, err = tRepos.Groups.GroupCreate(ctx, "test-group")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
tUser, err = tRepos.Users.Create(ctx, userFactory())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
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)
|
|
}
|
|
|
|
go func() {
|
|
_ = tbus.Run(context.Background())
|
|
}()
|
|
|
|
err = client.Schema.Create(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("failed creating schema resources: %v", err)
|
|
}
|
|
|
|
tClient = client
|
|
tRepos = New(tClient, tbus, os.TempDir())
|
|
defer func() { _ = client.Close() }()
|
|
|
|
bootstrap()
|
|
|
|
os.Exit(m.Run())
|
|
}
|