package pgxtest
import "github.com/jackc/pgx/v5/pgxtest"
Package pgxtest provides utilities for testing pgx and packages that integrate with pgx.
Index ¶
- Variables
- func RunValueRoundTripTests( ctx context.Context, t testing.TB, ctr ConnTestRunner, modes []pgx.QueryExecMode, pgTypeName string, tests []ValueRoundTripTest, )
- func RunWithQueryExecModes(ctx context.Context, t *testing.T, ctr ConnTestRunner, modes []pgx.QueryExecMode, f func(ctx context.Context, t testing.TB, conn *pgx.Conn))
- func SkipCockroachDB(t testing.TB, conn *pgx.Conn, msg string)
- func SkipPostgreSQLVersionLessThan(t testing.TB, conn *pgx.Conn, minVersion int64)
- type ConnTestRunner
- func DefaultConnTestRunner() ConnTestRunner
- func (ctr *ConnTestRunner) RunTest(ctx context.Context, t testing.TB, f func(ctx context.Context, t testing.TB, conn *pgx.Conn))
- type ValueRoundTripTest
Variables ¶
var AllQueryExecModes = []pgx.QueryExecMode{
pgx.QueryExecModeCacheStatement,
pgx.QueryExecModeCacheDescribe,
pgx.QueryExecModeDescribeExec,
pgx.QueryExecModeExec,
pgx.QueryExecModeSimpleProtocol,
}
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 ¶
SkipCockroachDB calls Skip on t with msg if the connection is to a CockroachDB server.
func SkipPostgreSQLVersionLessThan ¶
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 ¶
Source Files ¶
- Version
- v5.7.2 (latest)
- Published
- Dec 21, 2024
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 5 days ago –
Tools for package owners.