homebox/backend/internal/data/repo/main_test.go
Hayden faed343eda
fix: cookie-auth-issues (#365)
* fix session clearing on error

* use singleton context to manage user state

* implement remember-me functionality

* fix errors

* fix more errors
2023-03-22 21:52:25 -08:00

58 lines
1,000 B
Go

package repo
import (
"context"
"log"
"os"
"testing"
"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()
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)
}
err = client.Schema.Create(context.Background())
if err != nil {
log.Fatalf("failed creating schema resources: %v", err)
}
tClient = client
tRepos = New(tClient, os.TempDir())
defer client.Close()
bootstrap()
os.Exit(m.Run())
}