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/bouncer/internal/datastore/testsuite"
|
||
|
"forge.cadoles.com/cadoles/bouncer/internal/migrate"
|
||
|
"github.com/pkg/errors"
|
||
|
"gitlab.com/wpetit/goweb/logger"
|
||
|
|
||
|
_ "modernc.org/sqlite"
|
||
|
)
|
||
|
|
||
|
func TestSQLiteAgentRepository(t *testing.T) {
|
||
|
logger.SetLevel(logger.LevelDebug)
|
||
|
|
||
|
file := "testdata/agent_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 := NewProxyRepository(db)
|
||
|
|
||
|
testsuite.TestProxyRepository(t, repo)
|
||
|
}
|