47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/datastore/testsuite"
|
|
"forge.cadoles.com/Cadoles/emissary/internal/migrate"
|
|
"github.com/pkg/errors"
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
func TestSQLiteTenantRepository(t *testing.T) {
|
|
logger.SetLevel(logger.LevelDebug)
|
|
|
|
file := "testdata/tenant_repository_test.sqlite"
|
|
|
|
if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
dsn := fmt.Sprintf("%s?_pragma=foreign_keys(1)&_pragma=busy_timeout=%d", file, (60 * time.Second).Milliseconds())
|
|
|
|
migr, err := migrate.New("../../../migrations", "sqlite", "sqlite://"+dsn)
|
|
if err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
if err := migr.Up(); err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
db, err := sql.Open("sqlite", dsn)
|
|
if err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
repo := NewTenantRepository(db, 5)
|
|
|
|
testsuite.TestTenantRepository(t, repo)
|
|
}
|