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 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 := NewAgentRepository(db, 5) testsuite.TestAgentRepository(t, repo) }