refactor(backend): update test files for PoolProxy and per-test transactions

Migrate all test files from SetupTestDB/db.DB pattern to per-test transactions:

- Replace SetupTestDB(t) with SetupTestTx(t) for context + transaction
- Replace db.DB.Query/QueryRow/Exec with tx.Query/QueryRow/Exec
- Replace context.Background() with context from SetupTestTx
- Replace defer rows.Close() pattern with explicit rows.Close()
- Add testdb.SeedBaseline(pool) to all TestMain functions
- Wire db.Conn = db.NewPoolProxy(pool) in all TestMain functions

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-21 19:29:24 +01:00
co-authored by Sisyphus
parent 3d0e2afc4c
commit 220a0ef6e8
57 changed files with 5911 additions and 6235 deletions
+5 -8
View File
@@ -10,11 +10,9 @@ import (
"testing"
"crussell/db"
"crussell/testutils/testdb"
)
func TestHealthCheck_OK(t *testing.T) {
testdb.TruncateTables(t, db.DB)
// Create request and recorder
req := httptest.NewRequest(http.MethodGet, "/api/health", nil)
@@ -60,11 +58,10 @@ func TestHealthCheck_OK(t *testing.T) {
}
func TestHealthCheck_Degraded(t *testing.T) {
testdb.TruncateTables(t, db.DB)
// Set db.DB to nil to simulate degraded state
originalDB := db.DB
db.DB = nil
// Set db.Conn to nil to simulate degraded state
originalDB := db.Conn
db.Conn = nil
// Create request and recorder
req := httptest.NewRequest(http.MethodGet, "/api/health", nil)
@@ -102,6 +99,6 @@ func TestHealthCheck_Degraded(t *testing.T) {
t.Errorf("expected services.database 'error', got '%v'", services["database"])
}
// Restore original db.DB
db.DB = originalDB
// Restore original db.Conn
db.Conn = originalDB
}