Files
minstrel/internal/playlists/song_copies_test.go
T
bvandeusenandClaude Opus 5.5 39fa740bff test: one test-database opener, dbtest.Pool, in place of 39 copies (#8002)
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>
2026-11-26 12:49:02 -05:00

52 lines
1.7 KiB
Go

package playlists_test
import (
"context"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
)
// A mix holds a song once and never a held-back video rip: of a single and its
// album cut, the better-ranked copy stays; a rip is left out and the next copy
// of its song takes the place.
func TestOneCopyPerSong_Integration(t *testing.T) {
pool := dbtest.Pool(t)
ctx := context.Background()
q := dbq.New(pool)
single := seedTrack(t, pool, "copies-single", "copies-artist")
albumCut := seedTrack(t, pool, "copies-album-cut", "copies-artist")
rip := seedTrack(t, pool, "copies-rip", "copies-artist")
clean := seedTrack(t, pool, "copies-clean", "copies-artist")
other := seedTrack(t, pool, "copies-other", "copies-artist")
for _, pair := range [][]pgtype.UUID{{single.ID, albumCut.ID}, {rip.ID, clean.ID}} {
if _, err := q.LinkTracksAsSong(ctx, pair); err != nil {
t.Fatal(err)
}
}
if _, err := pool.Exec(ctx, `UPDATE tracks SET source_verdict = 'suspect' WHERE id = $1`, rip.ID); err != nil {
t.Fatal(err)
}
in := []playlists.RankedCandidate{
{TrackID: single.ID}, {TrackID: rip.ID}, {TrackID: albumCut.ID}, {TrackID: other.ID}, {TrackID: clean.ID},
}
out, err := playlists.OneCopyPerSong(ctx, q, in)
if err != nil {
t.Fatal(err)
}
want := []pgtype.UUID{single.ID, other.ID, clean.ID}
if len(out) != len(want) {
t.Fatalf("got %d tracks, want %d", len(out), len(want))
}
for i, w := range want {
if out[i].TrackID != w {
t.Errorf("position %d = %s, want %s", i, uuidString(out[i].TrackID), uuidString(w))
}
}
}