Documentation
¶
Overview ¶
Package pgbranchtest gives every Go test its own disposable Postgres database: Acquire creates a copy-on-write branch on a running pgbranch server (branchd), waits until it is ready, and destroys it when the test finishes.
func TestOrders(t *testing.T) {
b := pgbranchtest.Acquire(t)
db, _ := sql.Open("pgx", b.DSN)
// full production-shaped data, isolated writes
}
Configuration comes from the environment: PGBRANCH_SERVER (base URL of branchd; tests are skipped when unset — the SDK is integration-only by nature), PGBRANCH_TOKEN (API bearer token), PGBRANCH_TEST_SOURCE (default source name, else "main"), and PGBRANCH_PASSWORD (database password used in the returned DSNs; branch credentials are inherited from the source unless the server rotates them per branch and returns one).
The package is intentionally self-contained (stdlib only): it speaks the branchd REST API directly and never imports pgbranch internals.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Branch ¶
type Branch struct {
Name string
Host string
Port int
User string
Password string
Database string
DSN string
ProxyDSN string
}
Branch is an acquired database branch. DSN targets the branch's Postgres directly; ProxyDSN goes through the pgbranch wire-protocol router on the server host (port 6432, database "db@branch").
type Option ¶
type Option func(*config)
Option customizes Acquire.
func WithSource ¶
WithSource selects the source to branch from. Default: PGBRANCH_TEST_SOURCE, else "main".