dbtest

package
v0.96.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dbtest provides an isolated PostgreSQL handle for store tests.

Strategy (fast on slow disks): migrate ONE schema per test process, then make each test independent by TRUNCATEing its tables (milliseconds) instead of creating/migrating a fresh schema or database per test (hundreds of ms × thousands of tests → package timeouts). No test uses t.Parallel(), so within a process tests run sequentially and the truncate-between-tests is safe; across processes each gets its own schema (keyed by pid).

  • JACKUI_TEST_DATABASE_URL set → use that Postgres (the CI path).
  • otherwise → t.Skip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(t *testing.T) *sql.DB

NewDB returns a *sql.DB scoped to this process's migrated schema. On the first call within a test it TRUNCATEs all tables (re-seeding the anonymous user), so each test starts clean. Returns a fresh handle each call (safe to Close in the "closed pool" error-path tests without affecting other handles). Skips when no test database is configured.

func NewIsolatedDB

func NewIsolatedDB(t *testing.T) *sql.DB

NewIsolatedDB returns a pool scoped to a PRIVATE, freshly-migrated schema, dropped on cleanup. Slower than NewDB (full migration per call) — use it only for the rare tests that mutate the schema itself (e.g. DROP TABLE to force a store error), which can't share NewDB's process-wide schema.

func SeedUsers

func SeedUsers(t *testing.T, db *sql.DB, ids ...int64)

SeedUsers inserts users with the given ids (idempotent) so store tests can reference user_id FKs without standing up the auth store.

Types

This section is empty.

Jump to

Keyboard shortcuts

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