testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testutil boots a real, migrated Postgres for integration tests.

One shared pgvector-enabled container per test binary, migrated once, with tables truncated between tests rather than a database cloned per test.

Tests connect as a deliberately unprivileged role, not as the superuser the postgres image creates. That is load-bearing rather than tidiness: PostgreSQL exempts superusers from row-level security even when the table is FORCE'd, so a suite connecting as the default POSTGRES_USER would see every RLS policy silently do nothing and would pass whether or not tenant isolation actually works.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectScratchAs added in v0.3.0

func ConnectScratchAs(t *testing.T, pool *pgxpool.Pool, role, password string) *pgxpool.Pool

ConnectScratchAs connects to the database pool is connected to, as another role. It exists for tests that need to observe the database as an unprivileged role rather than as the owner — which is the only way to see row-level security do anything at all.

func SetupScratchDatabase

func SetupScratchDatabase(t *testing.T) *pgxpool.Pool

SetupScratchDatabase creates a fresh, empty database inside the shared container and returns an admin pool to it.

It exists so a test can run migrations — including rolling them back — without touching the migrated database every other test shares. Rolling back in the shared database would drop columns out from under whatever runs next.

func SetupTestPool

func SetupTestPool(t *testing.T) *pgxpool.Pool

SetupTestPool returns a pool connected to a shared, migrated Postgres as the unprivileged application role, starting the container on first use. It truncates the ragit tables via t.Cleanup so each test starts clean.

Skips under -short, so `go test -short ./...` needs no Docker.

Types

This section is empty.

Jump to

Keyboard shortcuts

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