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>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
||||
)
|
||||
|
||||
// seedTrackForArtist creates another track under an existing artist +
|
||||
@@ -108,7 +109,7 @@ func likeArtist(t *testing.T, pool *pgxpool.Pool, userID, artistID pgtype.UUID)
|
||||
func TestListDeepCutsTracks_SkippedTracksExcluded(t *testing.T) {
|
||||
// Eligibility counts skipped plays too, so a track skipped repeatedly
|
||||
// (and never finished) does not read as "barely heard".
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
q := dbq.New(pool)
|
||||
u := seedUser(t, pool, "dc1")
|
||||
now := time.Now().UTC()
|
||||
@@ -153,7 +154,7 @@ func TestListOnThisDayTracks_WrapsYearBoundary(t *testing.T) {
|
||||
// The day-of-year window wraps the year: plain ABS would make Dec 28 vs Jan
|
||||
// 3 read as 359 days apart. The build date parameter anchors "today" so the
|
||||
// wrap is testable at any run date.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
q := dbq.New(pool)
|
||||
u := seedUser(t, pool, "otd1")
|
||||
|
||||
@@ -186,7 +187,7 @@ func TestListNewForYouTracks_TiersAndConsumption(t *testing.T) {
|
||||
// affinity albums; tier 2 = affinity albums from the wider 90-day
|
||||
// window; tier 3 = fresh additions without affinity; any attempted
|
||||
// (>=30s) track consumes the album out of the mix entirely.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
q := dbq.New(pool)
|
||||
u := seedUser(t, pool, "nfy1")
|
||||
now := time.Now().UTC()
|
||||
@@ -243,7 +244,7 @@ func TestListFirstListensTracks_AttemptThreshold(t *testing.T) {
|
||||
// "Attempted" is track-level at >=30s. A 2-second brush does not
|
||||
// disqualify an album; barely-attempted albums step back
|
||||
// to tier 2 with the attempted tracks themselves excluded.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
q := dbq.New(pool)
|
||||
u := seedUser(t, pool, "fl1")
|
||||
now := time.Now().UTC()
|
||||
@@ -301,7 +302,7 @@ func TestListRediscoverTracks_SkippedResurfacingCoolsDown(t *testing.T) {
|
||||
// invitation — the track sits out ~90 days instead of re-qualifying
|
||||
// the next day. Skips from other surfaces don't cool down, and the
|
||||
// cooldown expires.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
q := dbq.New(pool)
|
||||
u := seedUser(t, pool, "rd1")
|
||||
now := time.Now().UTC()
|
||||
|
||||
Reference in New Issue
Block a user