forked from mirrors/homebox
31b34241e0
* change /content/ -> /homebox/ * add cache to code generators * update env variables to set data storage * update env variables * set env variables in prod container * implement attachment post route (WIP) * get attachment endpoint * attachment download * implement string utilities lib * implement generic drop zone * use explicit truncate * remove clean dir * drop strings composable for lib * update item types and add attachments * add attachment API * implement service context * consolidate API code * implement editing attachments * implement upload limit configuration * improve error handling * add docs for max upload size * fix test cases
62 lines
1 KiB
Go
62 lines
1 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"math/rand"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hay-kot/homebox/backend/ent"
|
|
"github.com/hay-kot/homebox/backend/pkgs/faker"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
var (
|
|
fk = faker.NewFaker()
|
|
|
|
tClient *ent.Client
|
|
tRepos *AllRepos
|
|
tUser *ent.User
|
|
tGroup *ent.Group
|
|
)
|
|
|
|
func bootstrap() {
|
|
var (
|
|
err error
|
|
ctx = context.Background()
|
|
)
|
|
|
|
tGroup, err = tRepos.Groups.Create(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) {
|
|
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)
|
|
}
|
|
|
|
err = client.Schema.Create(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("failed creating schema resources: %v", err)
|
|
}
|
|
|
|
tClient = client
|
|
tRepos = EntAllRepos(tClient)
|
|
defer client.Close()
|
|
|
|
bootstrap()
|
|
|
|
os.Exit(m.Run())
|
|
}
|