Every package carried its own testPool/newPool/newTestPool: skip under -short or without MINSTREL_TEST_DATABASE_URL, migrate, connect, register the close, and usually ResetDB. dbtest.Open does the first four (migrating once per test binary) and dbtest.Pool adds the reset. The per-package wrappers that did nothing else are gone; fixture helpers that seed rows keep their own signatures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package subsonic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
|
)
|
|
|
|
// A compilation's songs are credited to their own performers, as Subsonic
|
|
// clients show them, not all to Various Artists.
|
|
func TestGetAlbum_EachSongCreditsItsOwnArtist(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
|
|
ctx := context.Background()
|
|
q := dbq.New(pool)
|
|
artist := func(name string) dbq.Artist {
|
|
a, err := q.UpsertArtist(ctx, dbq.UpsertArtistParams{Name: name, SortName: name})
|
|
if err != nil {
|
|
t.Fatalf("artist %s: %v", name, err)
|
|
}
|
|
return a
|
|
}
|
|
various, first, guest := artist("Various Artists"), artist("Harbour Choir"), artist("Ruby Lane")
|
|
album, err := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: "Sunday Morning Static", SortTitle: "Sunday Morning Static", ArtistID: various.ID})
|
|
if err != nil {
|
|
t.Fatalf("album: %v", err)
|
|
}
|
|
n1, n2 := int32(1), int32(2)
|
|
for _, tr := range []dbq.UpsertTrackParams{
|
|
{Title: "Low Light", AlbumID: album.ID, ArtistID: first.ID, TrackNumber: &n1, FilePath: "/tmp/getalbum-1.flac", DurationMs: 100_000},
|
|
{Title: "Saltlines", AlbumID: album.ID, ArtistID: guest.ID, TrackNumber: &n2, FilePath: "/tmp/getalbum-2.flac", DurationMs: 100_000},
|
|
} {
|
|
if _, err := q.UpsertTrack(ctx, tr); err != nil {
|
|
t.Fatalf("track %s: %v", tr.Title, err)
|
|
}
|
|
}
|
|
|
|
b := &browseHandlers{pool: pool}
|
|
req := httptest.NewRequest(http.MethodGet, "/rest/getAlbum?f=json&id="+uuidToID(album.ID), nil)
|
|
w := httptest.NewRecorder()
|
|
b.getAlbum(w, req)
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("status = %d body=%s", w.Code, w.Body.String())
|
|
}
|
|
var raw struct {
|
|
Response struct {
|
|
Album AlbumDetail `json:"album"`
|
|
} `json:"subsonic-response"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &raw); err != nil {
|
|
t.Fatalf("decode: %v body=%s", err, w.Body.String())
|
|
}
|
|
got := raw.Response.Album
|
|
if got.Artist != "Various Artists" {
|
|
t.Errorf("album artist = %q, want Various Artists", got.Artist)
|
|
}
|
|
if len(got.Songs) != 2 || got.Songs[0].Artist != "Harbour Choir" || got.Songs[1].Artist != "Ruby Lane" {
|
|
t.Errorf("songs = %+v, want each song credited to its own artist", got.Songs)
|
|
}
|
|
}
|