pgtest

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgtest is a test-only helper for the PostgreSQL-gated suites (PG_TEST_DSN). It is imported exclusively from _test.go files, so it never becomes part of the production dependency graph, and it depends on nothing but sqlx so even the store package's own tests can use it.

Why it exists: CI runs every PG-gated test against a freshly created database, while a local development loop reuses one. Fixtures with a fixed identity — a site keyed on the unique (platform, url) pair, a downstream key with a constant value — then collide with the previous run's leftovers, and whole-table assertions count rows nobody seeded in this run. The failures are real red herrings: they say "duplicate key" or "total = 4, want 3" about state, not about the code under test. The documented escape hatch was "drop and recreate the database by hand before trusting a result", which is exactly the kind of tribal knowledge that makes a suite nobody dares to run twice.

Reset makes the local loop match CI: every PG-gated test starts from an empty database, so a suite is repeatable by construction and a second run of the same command is evidence rather than noise.

Run the PG suite the way CI does — serialized, one database:

PG_TEST_DSN=... go test ./... -count=1 -tags=integration -p 1

-p 1 is not optional: packages share one database, so parallel packages race each other on AutoMigrate and on this truncation (the CI workflow carries the same note). Tests inside a package already run sequentially.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reset

func Reset(t testing.TB, db *sqlx.DB)

Reset empties every user table in the current schema — except the migration bookkeeping table — and restarts identity sequences, so fixture primary keys are deterministic across runs. Call it right after opening the database and before AutoMigrate.

CASCADE is required because the schema is a web of foreign keys (sites → accounts → account_tokens → route_channels → …); enumerating a deletion order per test would be a second source of truth about the schema. Only tables outside pg_catalog/information_schema are touched, and the statement is built from quoted identifiers returned by PostgreSQL itself.

Types

This section is empty.

Jump to

Keyboard shortcuts

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