- 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
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"shared-album/internal/config"
|
|
"shared-album/internal/storage"
|
|
)
|
|
|
|
func mustSigner(t *testing.T) *storage.Signer {
|
|
t.Helper()
|
|
signer, err := storage.NewSigner("http://app.test", "secret", time.Hour)
|
|
if err != nil {
|
|
t.Fatalf("signer: %v", err)
|
|
}
|
|
return signer
|
|
}
|
|
|
|
func TestHealthStorageLabel(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
fs, err := storage.NewFS(t.TempDir(), mustSigner(t))
|
|
if err != nil {
|
|
t.Fatalf("fs: %v", err)
|
|
}
|
|
ok := func(context.Context) error { return nil }
|
|
srv := &Server{cfg: &config.Config{}, ping: ok, storage: fs}
|
|
|
|
call := func() map[string]any {
|
|
rec := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(rec)
|
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/health", nil)
|
|
srv.health(c)
|
|
var body map[string]any
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
return body
|
|
}
|
|
|
|
srv.cfg.Storage.Backend = "fs"
|
|
if body := call(); body["fs"] != "ok" {
|
|
t.Fatalf("expected fs label ok, got %v", body)
|
|
}
|
|
|
|
srv.cfg.Storage.Backend = "s3"
|
|
if body := call(); body["s3"] != "ok" {
|
|
t.Fatalf("expected s3 label ok, got %v", body)
|
|
}
|
|
|
|
srv.cfg.Storage.Backend = ""
|
|
if body := call(); body["s3"] != "ok" {
|
|
t.Fatalf("expected default s3 label, got %v", body)
|
|
}
|
|
}
|