599a19f780
submission=false → play_started (replaces in-memory nowPlayingMap). submission=true (default) → synthetic completed play. The nowPlayingMap struct + factory + the nowPlaying field on mediaHandlers are deleted; play_events WHERE ended_at IS NULL is now the source of truth for 'currently playing,' reachable from M3+ work. api.Mount now takes the shared *playevents.Writer instead of cfg so the same writer instance feeds both surfaces.
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package subsonic
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestFindSidecarCover(t *testing.T) {
|
|
dir := t.TempDir()
|
|
track := filepath.Join(dir, "01 - song.mp3")
|
|
if err := os.WriteFile(track, []byte("audio"), 0o644); err != nil {
|
|
t.Fatalf("write track: %v", err)
|
|
}
|
|
|
|
// Empty dir first: no cover.
|
|
if got := findSidecarCover(track); got != "" {
|
|
t.Errorf("no sidecar → %q, want empty", got)
|
|
}
|
|
|
|
// folder.jpg lower priority than cover.jpg: add folder first, expect hit;
|
|
// then add cover.jpg, expect cover to win.
|
|
folder := filepath.Join(dir, "folder.jpg")
|
|
if err := os.WriteFile(folder, []byte("jpg"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := findSidecarCover(track); got != folder {
|
|
t.Errorf("folder.jpg fallback = %q, want %q", got, folder)
|
|
}
|
|
cover := filepath.Join(dir, "cover.jpg")
|
|
if err := os.WriteFile(cover, []byte("jpg"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := findSidecarCover(track); got != cover {
|
|
t.Errorf("cover.jpg priority = %q, want %q", got, cover)
|
|
}
|
|
}
|
|
|
|
func TestImageContentType(t *testing.T) {
|
|
cases := map[string]string{
|
|
"cover.jpg": "image/jpeg",
|
|
"cover.JPEG": "image/jpeg",
|
|
"art.png": "image/png",
|
|
"thumb.gif": "image/gif",
|
|
"square.webp": "image/webp",
|
|
"unknown.tiff": "application/octet-stream",
|
|
}
|
|
for in, want := range cases {
|
|
if got := imageContentType(in); got != want {
|
|
t.Errorf("imageContentType(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|