Documentation
¶
Overview ¶
Package database provides test database utilities and helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestClient ¶
NewTestClient creates a test database client. In CI (when CI_DATABASE_URL is set): connects to external PostgreSQL service container. In local dev: spins up a testcontainer with PostgreSQL. The container/connection is automatically cleaned up when the test ends.
Types ¶
type SharedTestDB ¶
type SharedTestDB struct {
// contains filtered or unexported fields
}
SharedTestDB creates a single PostgreSQL schema that can be shared by multiple test replicas. Each replica gets its own connection pool via NewClient, but all pools point to the same schema — enabling cross-replica tests that exercise PostgreSQL NOTIFY/LISTEN event delivery.
func NewSharedTestDB ¶
func NewSharedTestDB(t *testing.T) *SharedTestDB
NewSharedTestDB creates a shared test schema, runs migrations and GIN indexes once, and registers t.Cleanup to drop the schema. Call NewClient to create independent database clients for each replica.
func (*SharedTestDB) NewClient ¶
func (s *SharedTestDB) NewClient(t *testing.T) *database.Client
NewClient creates an independent *database.Client backed by a fresh connection pool to the shared schema. Each client has its own pool so replicas can be shut down independently without races. The client's connections are closed via t.Cleanup.