Files
minstrel/internal/subsonic/getalbum_test.go
T
bvandeusenandClaude Opus 5.5 e1f270362d
release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
chore(release): everything that ships points at GitHub and GHCR (#7897)
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every
  import and the Dockerfile's version ldflags.
- buildinfo.ProjectURL, the contact outside services see in Minstrel's
  User-Agent: https://github.com/Fabled-Sword/minstrel.
- README's compose example pulls ghcr.io/fabled-sword/minstrel:latest.
- docs/security.md sends problem reports to the GitHub issues.
- The demo-library stack builds Minstrel from the checkout, since :dev
  is not published to GHCR.
- hygiene.go's same-site example uses example.com names.

The workbench CI (.gitea/, ci/, export-ignored) still builds and
publishes :dev to the private registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:28:16 -05:00

66 lines
2.2 KiB
Go

package subsonic
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
"github.com/Fabled-Sword/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)
}
}