pgxtest

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pgxtest provides utilities for testing pgx and packages that integrate with pgx.

Index

Constants

This section is empty.

Variables

View Source
var AllQueryExecModes = []pgx.QueryExecMode{
	pgx.QueryExecModeCacheStatement,
	pgx.QueryExecModeCacheDescribe,
	pgx.QueryExecModeDescribeExec,
	pgx.QueryExecModeExec,
	pgx.QueryExecModeSimpleProtocol,
}
View Source
var KnownOIDQueryExecModes = []pgx.QueryExecMode{
	pgx.QueryExecModeCacheStatement,
	pgx.QueryExecModeCacheDescribe,
	pgx.QueryExecModeDescribeExec,
}

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 SkipPostgreSQLVersionLessThan

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