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
+4 -18
View File
@@ -5,27 +5,20 @@ import (
"errors"
"io"
"log/slog"
"os"
"testing"
"time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
)
// triggerTestPool returns a pool against MINSTREL_TEST_DATABASE_URL or skips.
func triggerTestPool(t *testing.T) *pgxpool.Pool {
t.Helper()
url := os.Getenv("MINSTREL_TEST_DATABASE_URL")
if url == "" {
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
}
pool, err := pgxpool.New(context.Background(), url)
if err != nil {
t.Fatalf("connect: %v", err)
}
t.Cleanup(pool.Close)
pool := dbtest.Open(t)
// Reset scan_runs so each test starts clean.
if _, err := pool.Exec(context.Background(), `DELETE FROM scan_runs`); err != nil {
t.Fatalf("reset: %v", err)
@@ -135,14 +128,7 @@ func TestTryStartScan_StaleInFlight_Reaps(t *testing.T) {
}
func TestTryStartScan_DBError_Propagates(t *testing.T) {
url := os.Getenv("MINSTREL_TEST_DATABASE_URL")
if url == "" {
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
}
pool, err := pgxpool.New(context.Background(), url)
if err != nil {
t.Fatalf("connect: %v", err)
}
pool := dbtest.Open(t)
pool.Close() // close immediately to force errors on subsequent queries
started, existing, err := TryStartScan(