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:
2026-11-26 12:49:02 -05:00
co-authored by Claude Opus 5.5
parent 47e749225e
commit 39fa740bff
69 changed files with 329 additions and 975 deletions
+23 -22
View File
@@ -9,11 +9,12 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
)
func TestCreate_HappyPath(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
dir := t.TempDir()
@@ -37,7 +38,7 @@ func TestCreate_HappyPath(t *testing.T) {
}
func TestCreate_EmptyNameRejected(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -48,7 +49,7 @@ func TestCreate_EmptyNameRejected(t *testing.T) {
}
func TestGet_NotFound(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -59,7 +60,7 @@ func TestGet_NotFound(t *testing.T) {
}
func TestGet_Forbidden_PrivatePlaylistFromOtherUser(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -75,7 +76,7 @@ func TestGet_Forbidden_PrivatePlaylistFromOtherUser(t *testing.T) {
}
func TestGet_Public_VisibleToOtherUser(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -101,7 +102,7 @@ func TestGet_Public_VisibleToOtherUser(t *testing.T) {
}
func TestGet_Owner_SeesOwnPrivate(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -119,7 +120,7 @@ func TestGet_Owner_SeesOwnPrivate(t *testing.T) {
}
func TestList_OwnAndPublic(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -152,7 +153,7 @@ func TestList_OwnAndPublic(t *testing.T) {
}
func TestUpdate_OwnerOnly(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -177,7 +178,7 @@ func TestUpdate_OwnerOnly(t *testing.T) {
}
func TestUpdate_PartialFieldsLeaveOthersAlone(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -204,7 +205,7 @@ func TestUpdate_PartialFieldsLeaveOthersAlone(t *testing.T) {
}
func TestUpdate_EmptyNameRejected(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -220,7 +221,7 @@ func TestUpdate_EmptyNameRejected(t *testing.T) {
}
func TestUpdate_NotFound(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -231,7 +232,7 @@ func TestUpdate_NotFound(t *testing.T) {
}
func TestDelete_OwnerOnly(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -254,7 +255,7 @@ func TestDelete_OwnerOnly(t *testing.T) {
}
func TestDelete_NotFound(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -264,7 +265,7 @@ func TestDelete_NotFound(t *testing.T) {
}
func TestDelete_RemovesCoverFile(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
dir := t.TempDir()
svc := playlists.NewService(pool, nil, dir)
@@ -299,7 +300,7 @@ func TestDelete_RemovesCoverFile(t *testing.T) {
}
func TestDelete_MissingCoverFileTolerated(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
dir := t.TempDir()
svc := playlists.NewService(pool, nil, dir)
@@ -322,7 +323,7 @@ func TestDelete_MissingCoverFileTolerated(t *testing.T) {
}
func TestAppendTracks_Snapshot(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
track := seedTrack(t, pool, "Prismatic", "Fields of Ontario")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -348,7 +349,7 @@ func TestAppendTracks_Snapshot(t *testing.T) {
}
func TestAppendTracks_OwnerOnly(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
alice := seedUser(t, pool, "alice")
bob := seedUser(t, pool, "bob")
track := seedTrack(t, pool, "T", "A")
@@ -362,7 +363,7 @@ func TestAppendTracks_OwnerOnly(t *testing.T) {
}
func TestAppendTracks_NonExistentTrack(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -374,7 +375,7 @@ func TestAppendTracks_NonExistentTrack(t *testing.T) {
}
func TestRemoveTrack_RenumbersPositions(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
t1 := seedTrack(t, pool, "Track 1", "Artist")
t2 := seedTrack(t, pool, "Track 2", "Artist")
@@ -402,7 +403,7 @@ func TestRemoveTrack_RenumbersPositions(t *testing.T) {
}
func TestReorder_Permutation(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
t1 := seedTrack(t, pool, "A", "Artist")
t2 := seedTrack(t, pool, "B", "Artist")
@@ -427,7 +428,7 @@ func TestReorder_Permutation(t *testing.T) {
}
func TestReorder_RejectsNonPermutation(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
tk := seedTrack(t, pool, "T", "A")
svc := playlists.NewService(pool, nil, t.TempDir())
@@ -451,7 +452,7 @@ func TestReorder_RejectsNonPermutation(t *testing.T) {
}
func TestSnapshotPersistsAfterUpstreamTrackDelete(t *testing.T) {
pool := newPool(t)
pool := dbtest.Pool(t)
user := seedUser(t, pool, "alice")
tk := seedTrack(t, pool, "Doomed track", "Artist")
svc := playlists.NewService(pool, nil, t.TempDir())