pgtest

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pgtest provides a Postgres testing harness used by every Postgres-backed synapse store. It manages a single per-binary testcontainers Postgres instance and hands out fresh per-test databases backed by a pgxpool.

Usage from a backend's *_test.go:

func newStore(tb testing.TB) *mystore.Store {
    tb.Helper()
    pool := pgtest.Pool(tb)
    store, err := mystore.New(tb.Context(), pool)
    if err != nil { tb.Fatalf("New: %v", err) }
    return store
}

One container per test binary (initialized lazily on first Pool call), one database per test. Per-test databases are cleaned up after the test completes; the container is left running for the remainder of the binary's lifetime and is reaped when the process exits.

LISTEN/NOTIFY channels in Postgres are scoped per database, so the per-test database isolation extends to pub/sub state — exactly what the Postgres event store's subscription tests need.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pool

func Pool(tb testing.TB) *pgxpool.Pool

Pool returns a *pgxpool.Pool connected to a fresh per-test database. Lazily starts a Postgres container the first time it is called in the test binary; subsequent calls reuse the container.

The pool, the per-test database, and (eventually, on process exit) the container are cleaned up automatically. If Docker is unavailable or the container fails to start, Pool calls tb.Skip with a descriptive reason so tests degrade gracefully on machines without Docker.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL