ledgertest

package
v0.0.0-...-5453f10 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ledgertest provides throwaway, migrated Postgres databases for tests, without Docker.

Wire it into a test package with TestMain:

func TestMain(m *testing.M) { os.Exit(ledgertest.Run(m)) }

then call ledgertest.NewDB(t) in each test.

By default Run starts an embedded Postgres server (the binary is downloaded once and cached in ~/.embedded-postgres-go). Set LEDGER_TEST_DATABASE_URL to use an existing server instead, e.g. a local Homebrew Postgres:

LEDGER_TEST_DATABASE_URL=postgres://localhost:5432/postgres?sslmode=disable

Either way each NewDB call creates its own database, dropped when the test ends.

Index

Constants

View Source
const EnvDatabaseURL = "LEDGER_TEST_DATABASE_URL"

Variables

This section is empty.

Functions

func NewDB

func NewDB(t testing.TB) *bun.DB

NewDB returns a connection to a fresh database with the ledger schema migrated. The database is dropped when the test finishes.

func Run

func Run(m *testing.M) int

Run starts the test Postgres server if needed, runs the tests, and stops the server. It returns the exit code for os.Exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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