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) } }