Help us shape the future of Go! Take the 2026 Go Developer Survey

testdb

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testdb hands tests isolated, fully migrated PostgreSQL databases.

One PostgreSQL server is shared per test binary: either the one named by SLASHDOCS_TEST_DATABASE_URL (for CI environments without Docker) or a disposable container started via testcontainers. A template database is migrated once per schema version, and every call to New clones it, so each test gets a private database in a few milliseconds.

Index

Constants

View Source
const EnvURL = "SLASHDOCS_TEST_DATABASE_URL"

EnvURL is the environment variable that points tests at an existing PostgreSQL server instead of starting a container. The referenced role must be allowed to CREATE DATABASE.

Variables

This section is empty.

Functions

func New

func New(t testing.TB) string

New returns a connection string for a fresh database that already has all migrations applied. The database is private to the calling test and dropped on cleanup. If no PostgreSQL server is reachable (no Docker and no SLASHDOCS_TEST_DATABASE_URL), the calling test is skipped with an explanation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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