pgtest

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package pgtest supplies the live Postgres the pgstore, pglisten, pgnotify and pgpresence suites run against. It is test-only support code, shared because every one of those packages needs the same database and none should own the others' container.

A suite calls DSN() wherever it would otherwise hardcode a connection string. The database comes from one of two places:

  • SYNCPLANE_TEST_PG_DSN, if set — an already-running Postgres (a compose service, a CI service container, a local server). Nothing is torn down but the schemas the suite created.
  • a container started via testcontainers otherwise, once per test process.

When neither is reachable the specs SKIP rather than fail. Postgres is not a build dependency of this repo — sqlitestore is the adapter that ships with no infrastructure — so a contributor without Docker still runs everything else. CI has Docker and therefore runs these for real.

Each call returns a DSN scoped to a FRESH, EMPTY schema via search_path, and registers its teardown with Ginkgo. Schemas rather than databases because the conformance suite asks for an empty store more than a hundred times and CREATE DATABASE is far more expensive than CREATE SCHEMA — the isolation is the same for everything these adapters do, which is to say every table they create is unqualified and lands in the search_path's first entry.

Index

Constants

View Source
const DSNEnv = "SYNCPLANE_TEST_PG_DSN"

DSNEnv names the environment variable that points the suites at an existing Postgres instead of starting a container.

Variables

This section is empty.

Functions

func DSN

func DSN() string

DSN returns a connection string for a fresh, empty schema on the shared server, and registers the schema's teardown with the running spec. It SKIPS the spec when no Postgres is reachable.

func ServerDSN

func ServerDSN() string

ServerDSN returns a connection string for the shared server itself, with no schema of its own. It is for suites that need a database but no tables — the notifier, whose whole state is LISTEN/NOTIFY channels — and it SKIPS the spec when no Postgres is reachable, exactly as DSN does.

func Shutdown

func Shutdown()

Shutdown terminates the container started by this process, if any. Suites call it from AfterSuite. Testcontainers' reaper would eventually collect the container anyway; doing it explicitly keeps a developer's Docker clean between runs rather than at the reaper's convenience.

func UniqueName

func UniqueName(prefix string) string

UniqueName returns a fresh identifier with the given prefix, safe to use as a Postgres channel or schema name. Suites use it to keep specs that share one database from hearing each other.

Types

This section is empty.

Jump to

Keyboard shortcuts

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