price-is-wrong/pkg/lib/test.go

24 lines
412 B
Go

package lib
import (
"context"
"path"
"testing"
"gitea/price-is-wrong/pkg/lib/db"
_ "github.com/glebarez/sqlite"
)
func NewTestCtx(t *testing.T) context.Context {
d := t.TempDir()
p := path.Join(d, "db.db")
t.Logf("test db at %s", p)
b, err := db.New(context.Background(), "sqlite", p)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { b.Close() })
return db.Inject(context.Background(), b)
}