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

postgres

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package postgres provides opt-in, non-destructive PostgreSQL acceptance helpers. Callers supply only their isolated test database. No helper resets or drops data.

Index

Constants

View Source
const (
	URLVariable      = "FOUNDRY_TEST_POSTGRES_URL"
	RequiredVariable = "FOUNDRY_TEST_POSTGRES_REQUIRED"
)

Variables

This section is empty.

Functions

func Config

func Config(t testing.TB) postgres.Config

Config reads the explicitly opted-in URL. Ordinary test runs skip without it; the required acceptance command fails if it is missing. Errors omit credentials.

func Namespace

func Namespace(t testing.TB, db *database.DB) string

Namespace creates a unique schema in the caller's isolated test database. The returned identifier contains only safe ASCII letters, digits and underscores. Schemas are retained for inspection; no cleanup runs DROP/TRUNCATE or resets data.

func Open

func Open(t testing.TB, adjust ...func(*postgres.Config)) *database.DB

Open owns one test pool and registers bounded cleanup immediately. Optional adjustments operate on this test's independent settings before construction.

Types

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is one retained namespace in the explicitly opted-in test database. Configuration is immutable; each opened pool is independent and bounded.

func Isolate

func Isolate(t testing.TB) *Scope

Isolate allocates only a fresh schema. No database/server is created, and no teardown deletes data. The administration pool closes before this returns.

func (*Scope) Config

func (s *Scope) Config() postgres.Config

Config returns a caller-owned typed configuration for this retained scope. Scope creation uses the explicit URL, so no mutable TLS pointer is shared.

func (Scope) Format

func (Scope) Format(s fmt.State, _ rune)

Format writes a fixed label without exposing scope configuration.

func (*Scope) Open

func (s *Scope) Open(t testing.TB, options ...database.Option) *database.DB

Open owns a standalone scoped pool for fixtures/assertions. Prefer an app's actual database when testing application behavior or transaction ownership.

func (*Scope) Schema

func (s *Scope) Schema() string

Schema returns the test schema name, or an empty string for a nil scope.

Directories

Path Synopsis
Package application binds retained PostgreSQL scopes to production application settings.
Package application binds retained PostgreSQL scopes to production application settings.

Jump to

Keyboard shortcuts

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