pgxtest

package
v5.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 7 Imported by: 2 modules, 2 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 pgxtest provides utilities for testing pgx and packages that integrate with pgx.

Index

Constants

This section is empty.

Variables

KnownOIDQueryExecModes is a slice of all query exec modes where the param and result OIDs are known before sending the query.

Functions

func RunValueRoundTripTests

func RunValueRoundTripTests(
	ctx context.Context,
	t testing.TB,
	ctr ConnTestRunner,
	modes []pgx.QueryExecMode,
	pgTypeName string,
	tests []ValueRoundTripTest,
)

func RunWithQueryExecModes

func RunWithQueryExecModes(ctx context.Context, t *testing.T, ctr ConnTestRunner, modes []pgx.QueryExecMode, f func(ctx context.Context, t testing.TB, conn *pgx.Conn))

RunWithQueryExecModes runs a f in a new test for each element of modes with a new connection created using connector. If modes is nil all pgx.QueryExecModes are tested.

func SkipCockroachDB

func SkipCockroachDB(t testing.TB, conn *pgx.Conn, msg string)

SkipCockroachDB calls Skip on t with msg if the connection is to a CockroachDB server.

func SkipPostgreSQLVersionGreaterThan added in v5.9.0

func SkipPostgreSQLVersionGreaterThan(t testing.TB, conn *pgx.Conn, maxVersion int64)

func SkipPostgreSQLVersionLessThan added in v5.2.0

func SkipPostgreSQLVersionLessThan(t testing.TB, conn *pgx.Conn, minVersion int64)

Types

type ConnTestRunner

type ConnTestRunner struct {
	// CreateConfig returns a *pgx.ConnConfig suitable for use with pgx.ConnectConfig.
	CreateConfig func(ctx context.Context, t testing.TB) *pgx.ConnConfig

	// AfterConnect is called after conn is established. It allows for arbitrary connection setup before a test begins.
	AfterConnect func(ctx context.Context, t testing.TB, conn *pgx.Conn)

	// AfterTest is called after the test is run. It allows for validating the state of the connection before it is closed.
	AfterTest func(ctx context.Context, t testing.TB, conn *pgx.Conn)

	// CloseConn closes conn.
	CloseConn func(ctx context.Context, t testing.TB, conn *pgx.Conn)
}

ConnTestRunner controls how a *pgx.Conn is created and closed by tests. All fields are required. Use DefaultConnTestRunner to get a ConnTestRunner with reasonable default values.

func DefaultConnTestRunner

func DefaultConnTestRunner() ConnTestRunner

DefaultConnTestRunner returns a new ConnTestRunner with all fields set to reasonable default values.

func (*ConnTestRunner) RunTest

func (ctr *ConnTestRunner) RunTest(ctx context.Context, t testing.TB, f func(ctx context.Context, t testing.TB, conn *pgx.Conn))

type ValueRoundTripTest

type ValueRoundTripTest struct {
	Param  any
	Result any
	Test   func(any) bool
}

Jump to

Keyboard shortcuts

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