Build signed object URLs as path-only (/api/objects/...) instead of prefixing APP_BASE_URL, so media loads from whatever host or reverse proxy served the app. Remove the now-unused base URL from the signer and drop the APP_BASE_URL / Server.BaseURL config.
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"galo/internal/config"
|
|
"galo/internal/storage"
|
|
"galo/internal/video"
|
|
)
|
|
|
|
func mustSigner(t *testing.T) *storage.Signer {
|
|
t.Helper()
|
|
signer, err := storage.NewSigner("secret", time.Hour, 10*time.Minute)
|
|
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)
|
|
}
|
|
|
|
// A missing toolchain reports video unavailable without degrading the service.
|
|
if body := call(); body["video"] != "unavailable" {
|
|
t.Fatalf("expected video unavailable, got %v", body)
|
|
}
|
|
if body := call(); body["status"] != "ok" {
|
|
t.Fatalf("video unavailability must not degrade status, got %v", body)
|
|
}
|
|
|
|
// A resolvable toolchain reports video ok. The test binary is a known
|
|
// executable on every platform.
|
|
self, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatalf("executable: %v", err)
|
|
}
|
|
srv.videoTools = video.Detect(config.Video{FFmpegPath: self, FFprobePath: self})
|
|
if body := call(); body["video"] != "ok" {
|
|
t.Fatalf("expected video ok, got %v", body)
|
|
}
|
|
}
|