- handlers_test.go (//go:build red_gate): TestHealthz_OK, TestHealthz_Down, TestIndex_RendersHxGet, TestDemoTime_Fragment, TestRequestID_HeaderSet, TestSlog_HandlerSwitch — reference web.HealthzHandler / NewRouter / NewSlogHandler / Pinger to be implemented in Plan 01-03 - pool_test.go (//go:build red_gate): TestPool_Connects with t.Skip fallback when DATABASE_URL is unset - Build tag isolates the RED state from default 'go test ./...' (Codex #3)
33 lines
763 B
Go
33 lines
763 B
Go
//go:build red_gate
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestPool_Connects is an integration test that requires a live Postgres
|
|
// reachable via DATABASE_URL. Skipped in unit-test runs without the env var
|
|
// set. DSN value itself is never logged (info-disclosure T-01-06).
|
|
func TestPool_Connects(t *testing.T) {
|
|
dsn := os.Getenv("DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("DATABASE_URL not set — integration test skipped")
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
pool, err := NewPool(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatalf("NewPool: unexpected error: %v", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
if err := pool.Ping(ctx); err != nil {
|
|
t.Fatalf("pool.Ping: unexpected error: %v", err)
|
|
}
|
|
}
|