Files
Crussell/backend/db/db_test_init.go
T
popertotsandSisyphus 3d0e2afc4c refactor(backend): migrate db.DB to db.Conn PoolProxy across all handlers
Replace direct *pgxpool.Pool usage with PoolProxy wrapper across the entire backend:

- db.DB renamed to db.Conn (*pgxpool.Pool -> *PoolProxy)
- JWT functions now accept context.Context instead of using context.Background()
- Handler DB calls route through PoolProxy for per-test transaction support
- Fixture/helper/testdb functions accept Querier interface for decoupling
- Query ordering fixed in bookings handlers: COUNT after data query to avoid pgx conn busy
- Time truncation fixed: time.Date instead of Truncate(24*time.Hour) for week start calc
- testmain_test.go files updated with SeedBaseline and NewPoolProxy

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-21 19:28:54 +01:00

30 lines
641 B
Go

//go:build test
// +build test
package db
import (
"os"
)
// DB is a compatibility alias for Conn, for tests not yet migrated from db.Conn to db.Conn.
func init() {
// Set defaults for test environment if not already set
if os.Getenv("POSTGRES_USER") == "" {
os.Setenv("POSTGRES_USER", "myuser")
}
if os.Getenv("POSTGRES_PASSWORD") == "" {
os.Setenv("POSTGRES_PASSWORD", "mypassword")
}
if os.Getenv("POSTGRES_HOST") == "" {
os.Setenv("POSTGRES_HOST", "localhost")
}
if os.Getenv("POSTGRES_DB") == "" {
os.Setenv("POSTGRES_DB", "crussell_test")
}
if os.Getenv("GO_TESTING") == "" {
os.Setenv("GO_TESTING", "1")
}
}