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:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
||||
)
|
||||
|
||||
// TestHomeData_YouMightLike_FallbackFillsFromLikedArtists: when the taste
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
// You-might-like fallback fills the rest disjointly so no artist is shown
|
||||
// twice. 20 liked artists, none played → Rediscover 10 + You-might-like 10.
|
||||
func TestHomeData_YouMightLike_FallbackFillsFromLikedArtists(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-yml-fallback")
|
||||
liked := make(map[pgtype.UUID]bool, 20)
|
||||
for i := 0; i < 20; i++ {
|
||||
@@ -53,7 +54,7 @@ func TestHomeData_YouMightLike_FallbackFillsFromLikedArtists(t *testing.T) {
|
||||
// (most users like tracks/albums, rarely artists). 12 liked tracks by distinct
|
||||
// artists, no artist-likes, no plays → the artist row fills from them.
|
||||
func TestHomeData_YouMightLike_FallbackFromLikedTrackArtists(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-yml-trackartists")
|
||||
fromLiked := make(map[pgtype.UUID]bool, 12)
|
||||
for i := 0; i < 12; i++ {
|
||||
@@ -83,7 +84,7 @@ func TestHomeData_YouMightLike_FallbackFromLikedTrackArtists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHomeData_NewUser_AllSectionsEmpty(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-newuser")
|
||||
|
||||
got, err := HomeData(context.Background(), pool, user.ID)
|
||||
@@ -116,7 +117,7 @@ func TestHomeData_NewUser_AllSectionsEmpty(t *testing.T) {
|
||||
var _ map[pgtype.UUID]struct{}
|
||||
|
||||
func TestHomeData_RecentlyAdded_OrderedByCreatedAt(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-recents")
|
||||
a1 := seedArtist(t, pool, "ArtistA", "")
|
||||
// Three albums, oldest first — created_at increases naturally with each insert.
|
||||
@@ -142,7 +143,7 @@ func TestHomeData_RecentlyAdded_OrderedByCreatedAt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHomeData_MostPlayed_RanksByCount_HonorsQuarantine(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-mostplayed")
|
||||
artist := seedArtist(t, pool, "ArtistB", "")
|
||||
album := seedAlbumForArtist(t, pool, artist.ID, "AlbumB")
|
||||
@@ -179,7 +180,7 @@ func TestHomeData_MostPlayed_RanksByCount_HonorsQuarantine(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHomeData_RediscoverAlbums_FallbackWhenSparse(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-rediscover")
|
||||
artist := seedArtist(t, pool, "ArtistC", "")
|
||||
// Like one album NOW (won't satisfy >30d eligibility) — should still
|
||||
@@ -208,7 +209,7 @@ func TestHomeData_RediscoverAlbums_FallbackWhenSparse(t *testing.T) {
|
||||
// ago) is enough for the album to appear in Rediscover, even with no
|
||||
// explicit general_likes_albums entry.
|
||||
func TestHomeData_Rediscover_AlbumFromTrackLikes(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-redis-tracklike")
|
||||
artist := seedArtist(t, pool, "ArtistTL", "")
|
||||
al := seedAlbumForArtist(t, pool, artist.ID, "TrackLiked")
|
||||
@@ -240,7 +241,7 @@ func TestHomeData_Rediscover_AlbumFromTrackLikes(t *testing.T) {
|
||||
// track-derived path. The fallback should also miss this since no
|
||||
// album-like exists.
|
||||
func TestHomeData_Rediscover_AlbumTrackLikeThreshold(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-redis-threshold")
|
||||
artist := seedArtist(t, pool, "ArtistTh", "")
|
||||
al := seedAlbumForArtist(t, pool, artist.ID, "OneTrackLiked")
|
||||
@@ -265,7 +266,7 @@ func TestHomeData_Rediscover_AlbumTrackLikeThreshold(t *testing.T) {
|
||||
// albums from the same artist appear in Rediscover even when more are
|
||||
// eligible.
|
||||
func TestHomeData_Rediscover_DiversityCap(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-redis-cap")
|
||||
artist := seedArtist(t, pool, "ArtistDom", "")
|
||||
albums := []dbq.Album{
|
||||
@@ -299,7 +300,7 @@ func TestHomeData_Rediscover_DiversityCap(t *testing.T) {
|
||||
// dropped from Rediscover (the "you forgot about this" contract is
|
||||
// broken if the user is actively spinning it).
|
||||
func TestHomeData_Rediscover_DedupVsMostPlayed(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
user := seedUser(t, pool, "home-redis-dedup")
|
||||
artist := seedArtist(t, pool, "ArtistD", "")
|
||||
// "Forgotten" album: liked >30d ago, no recent plays — would be
|
||||
|
||||
Reference in New Issue
Block a user