testdb

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 9 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 testdb connects integration tests to PostgreSQL.

Tests that need a database call Pool. They are skipped when the TASKMILL_TEST_DATABASE_URL environment variable is unset; `make test` sets it to the database that `make db` starts. Each test gets its own schema, so tests can run in parallel and leave nothing behind.

To run the tests through a transaction-pooling proxy such as PgBouncer, point TASKMILL_TEST_DATABASE_URL at the proxy and TASKMILL_TEST_LISTEN_URL at the database itself: workers then listen for notifications on a direct connection, which the proxy cannot provide.

Index

Constants

View Source
const (
	EnvURL       = "TASKMILL_TEST_DATABASE_URL" // the test database URL
	EnvListenURL = "TASKMILL_TEST_LISTEN_URL"   // a direct URL, if EnvURL goes through a proxy
)

Environment variables that configure the test database.

Variables

This section is empty.

Functions

func CheckGroups added in v0.2.0

func CheckGroups(tb testing.TB, pool *pgxpool.Pool, schema string)

CheckGroups fails the test unless every FIFO group of schema satisfies the invariants in docs/design/task-lifecycle.md: its count matches its unfinished tasks plus a halting dead head, it has exactly one head, and every unfinished grouped task belongs to a group row.

func DirectURL added in v0.2.0

func DirectURL(tb testing.TB) string

DirectURL returns a URL that reaches the test database without a proxy: EnvListenURL if it is set, or else EnvURL. Tests that set connection parameters, which proxies refuse, connect with it.

func ListenConfig added in v0.2.0

func ListenConfig(tb testing.TB) *pgx.ConnConfig

ListenConfig returns the connection that workers listen on: EnvListenURL's, or nil if it is unset, which makes workers listen on their pools'.

func Pool

func Pool(tb testing.TB) *pgxpool.Pool

Pool returns a pool of up to 8 connections to the test database, closed when the test ends.

func PoolSize

func PoolSize(tb testing.TB, conns int32) *pgxpool.Pool

PoolSize is Pool with a given number of connections, for tests that run many operations at once.

func Schema

func Schema(tb testing.TB, pool *pgxpool.Pool) string

Schema returns a fresh schema name, and drops that schema when the test ends.

func URL

func URL(tb testing.TB) string

URL returns the test database URL, or skips the test if none is set.

Types

This section is empty.

Jump to

Keyboard shortcuts

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