2022-08-30 02:30:36 +00:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-08-02 21:00:57 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/core/services/reporting/eventbus"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
2022-09-24 19:33:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/pkgs/faker"
|
2022-08-30 02:30:36 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
2022-08-31 03:21:18 +00:00
|
|
|
var (
|
2023-11-16 03:17:43 +00:00
|
|
|
fk = faker.NewFaker()
|
|
|
|
tbus = eventbus.New()
|
2022-09-05 08:26:21 +00:00
|
|
|
|
|
|
|
tClient *ent.Client
|
|
|
|
tRepos *AllRepos
|
2022-09-27 23:52:13 +00:00
|
|
|
tUser UserOut
|
2022-10-07 02:54:09 +00:00
|
|
|
tGroup Group
|
2022-08-31 03:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func bootstrap() {
|
2022-09-05 08:26:21 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
ctx = context.Background()
|
|
|
|
)
|
2022-08-31 03:21:18 +00:00
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
tGroup, err = tRepos.Groups.GroupCreate(ctx, "test-group")
|
2022-09-05 08:26:21 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2022-08-31 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 08:26:21 +00:00
|
|
|
tUser, err = tRepos.Users.Create(ctx, userFactory())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2022-08-31 03:21:18 +00:00
|
|
|
}
|
2022-08-30 02:30:36 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-03-02 00:07:03 +00:00
|
|
|
go func() {
|
|
|
|
_ = tbus.Run(context.Background())
|
|
|
|
}()
|
2023-08-02 21:00:57 +00:00
|
|
|
|
2022-09-05 08:26:21 +00:00
|
|
|
err = client.Schema.Create(context.Background())
|
|
|
|
if err != nil {
|
2022-08-30 02:30:36 +00:00
|
|
|
log.Fatalf("failed creating schema resources: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-09-05 08:26:21 +00:00
|
|
|
tClient = client
|
2023-08-02 21:00:57 +00:00
|
|
|
tRepos = New(tClient, tbus, os.TempDir())
|
2022-08-30 02:30:36 +00:00
|
|
|
|
2022-08-31 03:21:18 +00:00
|
|
|
bootstrap()
|
2022-08-30 02:30:36 +00:00
|
|
|
|
2024-04-28 17:21:43 +00:00
|
|
|
exit := m.Run()
|
|
|
|
_ = client.Close()
|
|
|
|
os.Exit(exit)
|
2022-08-30 02:30:36 +00:00
|
|
|
}
|