forked from mirrors/homebox
tests: improve repo package coverage (#3)
* refactor and add repo tests * add CI name * use atomic for test shutdown * use go 1.19 * add timeout
This commit is contained in:
parent
888ecfde34
commit
508e2e59bd
20 changed files with 540 additions and 186 deletions
|
@ -9,25 +9,34 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hay-kot/content/backend/ent"
|
||||
"github.com/hay-kot/content/backend/pkgs/faker"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var (
|
||||
testEntClient *ent.Client
|
||||
testRepos *AllRepos
|
||||
testUser *ent.User
|
||||
testGroup *ent.Group
|
||||
fk = faker.NewFaker()
|
||||
|
||||
tClient *ent.Client
|
||||
tRepos *AllRepos
|
||||
tUser *ent.User
|
||||
tGroup *ent.Group
|
||||
)
|
||||
|
||||
func bootstrap() {
|
||||
ctx := context.Background()
|
||||
testGroup, _ = testRepos.Groups.Create(ctx, "test-group")
|
||||
testUser, _ = testRepos.Users.Create(ctx, UserFactory())
|
||||
var (
|
||||
err error
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
if testGroup == nil || testUser == nil {
|
||||
log.Fatal("Failed to bootstrap test data")
|
||||
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) {
|
||||
|
@ -38,12 +47,13 @@ func TestMain(m *testing.M) {
|
|||
log.Fatalf("failed opening connection to sqlite: %v", err)
|
||||
}
|
||||
|
||||
if err := client.Schema.Create(context.Background()); err != nil {
|
||||
err = client.Schema.Create(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
|
||||
testEntClient = client
|
||||
testRepos = EntAllRepos(testEntClient)
|
||||
tClient = client
|
||||
tRepos = EntAllRepos(tClient)
|
||||
defer client.Close()
|
||||
|
||||
bootstrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue