mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-17 06:08:42 +00:00
95ab14b866
* format readme * update logo * format html * add logo to docs * repository for document and document tokens * add attachments type and repository * autogenerate types via scripts * use autogenerated types * attachment type updates * add insured and quantity fields for items * implement HasID interface for entities * implement label updates for items * implement service update method * WIP item update client side actions * check err on attachment * finish types for basic items editor * remove unused var * house keeping
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"math/rand"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hay-kot/content/backend/ent"
|
|
"github.com/hay-kot/content/backend/internal/repo"
|
|
"github.com/hay-kot/content/backend/internal/types"
|
|
"github.com/hay-kot/content/backend/pkgs/faker"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
var (
|
|
fk = faker.NewFaker()
|
|
|
|
tClient *ent.Client
|
|
tRepos *repo.AllRepos
|
|
tUser *ent.User
|
|
tGroup *ent.Group
|
|
tSvc *AllServices
|
|
)
|
|
|
|
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, types.UserCreate{
|
|
Name: fk.Str(10),
|
|
Email: fk.Email(),
|
|
Password: fk.Str(10),
|
|
IsSuperuser: fk.Bool(),
|
|
GroupID: tGroup.ID,
|
|
})
|
|
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 = repo.EntAllRepos(tClient)
|
|
tSvc = NewServices(tRepos)
|
|
defer client.Close()
|
|
|
|
bootstrap()
|
|
|
|
os.Exit(m.Run())
|
|
}
|