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/stretchr/testify/require"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/mailer"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||||
)
|
||||
@@ -30,7 +31,7 @@ func digestWith(pool *pgxpool.Pool) (*notifications.Digest, *mailer.FakeSender)
|
||||
}
|
||||
|
||||
func TestDigest_BatchGoesOutOnceAWindowAfterTheFirstItem(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
alice := emailUser(t, pool, "alice", true)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
@@ -57,7 +58,7 @@ func TestDigest_BatchGoesOutOnceAWindowAfterTheFirstItem(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_ReadBeforeTheEmailIsNotEmailed(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
alice := emailUser(t, pool, "alice", true)
|
||||
@@ -74,7 +75,7 @@ func TestDigest_ReadBeforeTheEmailIsNotEmailed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_EmailOffAtNotifyTimeIsNeverSent(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
alice := emailUser(t, pool, "alice", true)
|
||||
@@ -99,7 +100,7 @@ func TestDigest_EmailOffAtNotifyTimeIsNeverSent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_NoAddressNoEmail(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
bob := mkUser(t, dbq.New(pool), "bob", true)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
@@ -111,7 +112,7 @@ func TestDigest_NoAddressNoEmail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_CoalescedItemAppearsOnceWithItsLatestCount(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
root := emailUser(t, pool, "root", true)
|
||||
@@ -134,7 +135,7 @@ func TestDigest_CoalescedItemAppearsOnceWithItsLatestCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_MailerFailureRetriesWithBackoffAndSendsOnce(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
alice := emailUser(t, pool, "alice", true)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
@@ -158,7 +159,7 @@ func TestDigest_MailerFailureRetriesWithBackoffAndSendsOnce(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_NewMusicWaitsForTheSummaryHour(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
alice := emailUser(t, pool, "alice", true) // timezone defaults to UTC
|
||||
n := notifications.New(pool, nil, nil)
|
||||
@@ -192,7 +193,7 @@ func TestDigest_NewMusicWaitsForTheSummaryHour(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEmailSettings_DefaultsMatchTheMigrationAndRoundTrip(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
|
||||
@@ -209,7 +210,7 @@ func TestEmailSettings_DefaultsMatchTheMigrationAndRoundTrip(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDigest_UsesTheConfiguredBatchWindow(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
pool := dbtest.Pool(t)
|
||||
ctx := context.Background()
|
||||
alice := emailUser(t, pool, "alice", true)
|
||||
_, err := notifications.SaveEmailSettings(ctx, dbq.New(pool), notifications.EmailSettings{SummaryHour: 9, BatchWindowMinutes: 15})
|
||||
|
||||
Reference in New Issue
Block a user