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:
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
|
||||
)
|
||||
|
||||
@@ -79,7 +80,7 @@ func seedActiveLibrary(t *testing.T, pool *pgxpool.Pool, name string, numArtists
|
||||
}
|
||||
|
||||
func TestBuildSystemPlaylists_SufficientActivity(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedActiveLibrary(t, pool, "act1", 4, 3)
|
||||
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), t.TempDir()); err != nil {
|
||||
@@ -146,7 +147,7 @@ func TestBuildSystemPlaylists_StaleActivity_SongsLikeSurvives(t *testing.T) {
|
||||
// inside 30d) must still seed the mixes —
|
||||
// and the built tracks carry the tier2 stamp so metrics can compare
|
||||
// stale-seeded mixes against fresh ones.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u := seedUser(t, pool, "stale1")
|
||||
old := time.Now().UTC().Add(-20 * 24 * time.Hour)
|
||||
@@ -193,7 +194,7 @@ func TestBuildSystemPlaylists_StaleActivity_SongsLikeSurvives(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildSystemPlaylists_QuarantineExcluded(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, tracks := seedActiveLibrary(t, pool, "qact", 3, 3)
|
||||
|
||||
@@ -228,7 +229,7 @@ func TestBuildSystemPlaylists_QuarantineExcluded(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildSystemPlaylists_AtomicReplace(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedActiveLibrary(t, pool, "atomic", 3, 3)
|
||||
ctx := context.Background()
|
||||
@@ -265,7 +266,7 @@ func TestBuildSystemPlaylists_AtomicReplace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildSystemPlaylists_Concurrency(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedActiveLibrary(t, pool, "conc", 3, 3)
|
||||
ctx := context.Background()
|
||||
@@ -361,7 +362,7 @@ func seedSharedArtistLibrary(
|
||||
// to survive a filter coming back in a different shape — and because an
|
||||
// absence check would match the comment explaining why there is no filter.
|
||||
func TestBuildSystemPlaylists_SongsLikeIncludesItsSeedArtist(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedSharedArtistLibrary(t, pool, "seedartist", 4, 6)
|
||||
ctx := context.Background()
|
||||
@@ -423,7 +424,7 @@ func TestBuildSystemPlaylists_SongsLikeIncludesItsSeedArtist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildSystemPlaylists_DailyNonceDeterminism(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedActiveLibrary(t, pool, "nonce", 4, 5)
|
||||
ctx := context.Background()
|
||||
@@ -538,7 +539,7 @@ func equalSnapshots(a, b map[string][]string) bool {
|
||||
}
|
||||
|
||||
func TestListActiveUsersForSystemPlaylists(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
activeU, tracks := seedActiveLibrary(t, pool, "active", 1, 1)
|
||||
inactiveU := seedUser(t, pool, "inactive")
|
||||
@@ -570,7 +571,7 @@ func TestListActiveUsersForSystemPlaylists(t *testing.T) {
|
||||
func TestBuildSystemPlaylists_DiscoverColdStart(t *testing.T) {
|
||||
// User has no plays / likes → Discover's dormant + cross-user
|
||||
// buckets are empty (or minimal), all slots come from random unheard.
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
logger := discardLogger()
|
||||
u, _ := seedActiveLibrary(t, pool, "discover_cold", 4, 5)
|
||||
// seedActiveLibrary seeds 3 plays per track; delete them so dormant
|
||||
@@ -619,7 +620,7 @@ func systemVariantsOf(rows []dbq.ListPlaylistsByUserAndKindRow) []string {
|
||||
}
|
||||
|
||||
func TestStartupRecoveryClearsStaleInFlight(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
u := seedUser(t, pool, "stale")
|
||||
// Seed a stale in_flight=true row.
|
||||
|
||||
Reference in New Issue
Block a user