All checks were successful
Check / check (push) Successful in 1m16s
Changes the Go module path from `git.eeqj.de/sneak/upaas` to `sneak.berlin/go/upaas`. All import paths in Go files updated accordingly. `go mod tidy` and `make check` pass cleanly. fixes #143 Co-authored-by: user <user@Mac.lan guest wan> Co-authored-by: Jeffrey Paul <sneak@noreply.example.org> Reviewed-on: #149 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
42 lines
719 B
Go
42 lines
719 B
Go
package database
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/upaas/internal/config"
|
|
"sneak.berlin/go/upaas/internal/logger"
|
|
)
|
|
|
|
// NewTestDatabase creates an in-memory Database for testing.
|
|
// It runs migrations so all tables are available.
|
|
func NewTestDatabase(t *testing.T) *Database {
|
|
t.Helper()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
cfg := &config.Config{
|
|
DataDir: tmpDir,
|
|
}
|
|
|
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
|
logWrapper := logger.NewForTest(log)
|
|
|
|
db, err := New(nil, Params{
|
|
Logger: logWrapper,
|
|
Config: cfg,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("failed to create test database: %v", err)
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
if db.database != nil {
|
|
_ = db.database.Close()
|
|
}
|
|
})
|
|
|
|
return db
|
|
}
|