- pluggable per-domain Repository interfaces; PostgreSQL and SQLite impls - SQLite on modernc.org/sqlite (WAL, busy_timeout, foreign_keys, immediate tx) - separate migrations/sqlite and db.MigrateSQLite; store.NewPostgres/NewSQLite - cmd/reconcile compares object storage with the journal (report, then --delete) - storage.Backend.List and photos.Repository.AllStorageKeys - DB_BACKEND/SQLITE_PATH and STORAGE_BACKEND/FS_ROOT selectable; local defaults (sqlite ./galo.db, fs ./data) - Makefile reconcile/reconcile-delete; docs and .env.example updated
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
assets "shared-album"
|
|
"shared-album/internal/db"
|
|
)
|
|
|
|
func assertComplete(t *testing.T, r Repos) {
|
|
t.Helper()
|
|
if r.Auth == nil || r.Albums == nil || r.Members == nil || r.Photos == nil ||
|
|
r.Social == nil || r.Notifications == nil || r.ShareLinks == nil {
|
|
t.Fatalf("incomplete repository bundle: %+v", r)
|
|
}
|
|
}
|
|
|
|
func TestNewSQLite(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "meta.db")
|
|
migFS, err := fs.Sub(assets.Migrations, "migrations/sqlite")
|
|
if err != nil {
|
|
t.Fatalf("migrations fs: %v", err)
|
|
}
|
|
if err := db.MigrateSQLite(path, migFS); err != nil {
|
|
t.Fatalf("migrate: %v", err)
|
|
}
|
|
database, err := db.OpenSQLite(path)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer database.Close()
|
|
assertComplete(t, NewSQLite(database))
|
|
}
|
|
|
|
func TestNewPostgres(t *testing.T) {
|
|
dsn := os.Getenv("TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("TEST_DATABASE_URL not set")
|
|
}
|
|
pool, err := pgxpool.New(context.Background(), dsn)
|
|
if err != nil {
|
|
t.Skipf("cannot connect: %v", err)
|
|
}
|
|
if err := pool.Ping(context.Background()); err != nil {
|
|
t.Skipf("cannot ping: %v", err)
|
|
}
|
|
t.Cleanup(pool.Close)
|
|
assertComplete(t, NewPostgres(pool))
|
|
}
|