Documentation
¶
Overview ¶
Package pgxtest provides utilities for testing pgx and packages that integrate with pgx.
Index ¶
Constants ¶
This section is empty.
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.
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.
type ValueRoundTripTest ¶
type ValueRoundTripTest struct { Param interface{} Result interface{} Test func(interface{}) bool }