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

testpg

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package testpg provides isolated PostgreSQL schemas and migrated template databases for tests and the system-test server.

Index

Constants

View Source
const RunTokenEnv = "SYNAPS3_TEST_RUN_TOKEN"

RunTokenEnv identifies resources owned by one test-command invocation.

Variables

This section is empty.

Functions

func BaseDSN

func BaseDSN() (string, error)

BaseDSN returns SYNAPS3_POSTGRES_TEST_DSN when set; otherwise it starts one PostgreSQL container per process.

func BaseDSNContext added in v0.1.1

func BaseDSNContext(ctx context.Context) (string, error)

BaseDSNContext initializes this process's PostgreSQL service within ctx.

func CleanupRun added in v0.1.1

func CleanupRun(ctx context.Context, dsn, token string) (result error)

CleanupRun reclaims only resources in token's namespace owned by the DSN role. The database named by dsn is a maintenance connection and is never removed.

func Close

func Close() error

Close cleans up this process's registered databases and schemas, then terminates only the container it created. Call after m.Run.

func CreateSchema

func CreateSchema(ctx context.Context, dsn string) (string, func(context.Context) error, error)

CreateSchema creates an empty private schema in the database named by dsn and returns a DSN whose connections use it. Close every connection to the returned DSN before calling drop.

func DSN

func DSN(t *testing.T) string

DSN returns the external test DSN or starts one PostgreSQL container per process.

func Main

func Main(m *testing.M)

Main runs a package's tests, cleans up this process's registered databases and schemas, then terminates its own container. Call it from TestMain.

func NewRunToken added in v0.1.1

func NewRunToken() (string, error)

NewRunToken returns an unpredictable namespace for one test invocation.

func SchemaDSN

func SchemaDSN(t *testing.T) string

SchemaDSN creates an empty private schema and sets search_path on every connection. Register connection cleanup after calling it so connections close before the schema.

Types

type Template added in v0.1.1

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

Template owns an immutable migrated database for this test process.

func NewTemplate added in v0.1.1

func NewTemplate(ctx context.Context, prepare func(context.Context, *pgx.ConnConfig) error) (_ *Template, result error)

NewTemplate prepares a database with a private schema for cloning. prepare must close all connections it opens before returning.

func (*Template) Clone added in v0.1.1

func (template *Template) Clone(ctx context.Context) (*pgx.ConnConfig, func(context.Context) error, error)

Clone returns a fresh database with real independent transactions and catalogs. Close all connections to the clone before invoking its cleanup function.

Directories

Path Synopsis
cmd
testrun command

Jump to

Keyboard shortcuts

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