From e18d76b7983e52bc1f5b0206d6fee7fbf7d5406f Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 2 Apr 2022 10:26:47 -0500 Subject: [PATCH] Initial extraction of pgxtest - Introduce ConnTestRunner - RunWithQueryExecModes --- batch_test.go | 23 ++++++------ conn_test.go | 23 ++++++------ helper_test.go | 40 +++++---------------- pgxtest/pgxtest.go | 88 ++++++++++++++++++++++++++++++++++++++++++++++ query_test.go | 7 ++-- values_test.go | 57 +++++++++++++++--------------- 6 files changed, 154 insertions(+), 84 deletions(-) create mode 100644 pgxtest/pgxtest.go diff --git a/batch_test.go b/batch_test.go index 3e5a2d46..ffd990fc 100644 --- a/batch_test.go +++ b/batch_test.go @@ -8,6 +8,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ import ( func TestConnSendBatch(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server serial type is incompatible with test") sql := `create temporary table ledger( @@ -149,7 +150,7 @@ func TestConnSendBatch(t *testing.T) { func TestConnSendBatchMany(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `create temporary table ledger( id serial primary key, description varchar not null, @@ -194,7 +195,7 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) { pgx.QueryExecModeExec, // Don't test simple mode with prepared statements. } - testWithQueryExecModes(t, modes, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, modes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)") _, err := conn.Prepare(context.Background(), "ps1", "select n from generate_series(0,$1::int) n") if err != nil { @@ -300,7 +301,7 @@ func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing. func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { batch := &pgx.Batch{} batch.Queue("select n from generate_series(0,5) n") @@ -359,7 +360,7 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) { func TestConnSendBatchQueryError(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { batch := &pgx.Batch{} batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0") @@ -397,7 +398,7 @@ func TestConnSendBatchQueryError(t *testing.T) { func TestConnSendBatchQuerySyntaxError(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { batch := &pgx.Batch{} batch.Queue("select 1 1") @@ -421,7 +422,7 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) { func TestConnSendBatchQueryRowInsert(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `create temporary table ledger( id serial primary key, @@ -458,7 +459,7 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) { func TestConnSendBatchQueryPartialReadInsert(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `create temporary table ledger( id serial primary key, @@ -495,7 +496,7 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) { func TestTxSendBatch(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `create temporary table ledger1( id serial primary key, @@ -562,7 +563,7 @@ func TestTxSendBatch(t *testing.T) { func TestTxSendBatchRollback(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `create temporary table ledger1( id serial primary key, @@ -597,7 +598,7 @@ func TestTxSendBatchRollback(t *testing.T) { func TestConnBeginBatchDeferredError(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") diff --git a/conn_test.go b/conn_test.go index 625d9693..31190d7c 100644 --- a/conn_test.go +++ b/conn_test.go @@ -11,6 +11,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -198,7 +199,7 @@ func TestParseConfigExtractsDefaultQueryExecMode(t *testing.T) { func TestExec(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results.String() != "CREATE TABLE" { t.Error("Unexpected results from Exec") } @@ -232,7 +233,7 @@ func TestExec(t *testing.T) { func TestExecFailure(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { if _, err := conn.Exec(context.Background(), "selct;"); err == nil { t.Fatal("Expected SQL syntax error") } @@ -248,7 +249,7 @@ func TestExecFailure(t *testing.T) { func TestExecFailureWithArguments(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { _, err := conn.Exec(context.Background(), "selct $1;", 1) if err == nil { t.Fatal("Expected SQL syntax error") @@ -263,7 +264,7 @@ func TestExecFailureWithArguments(t *testing.T) { func TestExecContextWithoutCancelation(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -281,7 +282,7 @@ func TestExecContextWithoutCancelation(t *testing.T) { func TestExecContextFailureWithoutCancelation(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -303,7 +304,7 @@ func TestExecContextFailureWithoutCancelation(t *testing.T) { func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -680,7 +681,7 @@ func TestFatalTxError(t *testing.T) { func TestInsertBoolArray(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results.String() != "CREATE TABLE" { t.Error("Unexpected results from Exec") } @@ -695,7 +696,7 @@ func TestInsertBoolArray(t *testing.T) { func TestInsertTimestampArray(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results.String() != "CREATE TABLE" { t.Error("Unexpected results from Exec") } @@ -819,7 +820,7 @@ func TestConnInitTypeMap(t *testing.T) { } func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) { - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)") var n uint64 @@ -835,7 +836,7 @@ func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) { } func TestDomainType(t *testing.T) { - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)") // Domain type uint64 is a PostgreSQL domain of underlying type numeric. @@ -1006,7 +1007,7 @@ func TestStmtCacheInvalidationTx(t *testing.T) { } func TestInsertDurationInterval(t *testing.T) { - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { _, err := conn.Exec(context.Background(), "create temporary table t(duration INTERVAL(0) NOT NULL)") require.NoError(t, err) diff --git a/helper_test.go b/helper_test.go index 26509946..e0f04906 100644 --- a/helper_test.go +++ b/helper_test.go @@ -9,40 +9,18 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/require" ) -func testWithAllQueryExecModes(t *testing.T, f func(t *testing.T, conn *pgx.Conn)) { - modes := []pgx.QueryExecMode{ - pgx.QueryExecModeCacheStatement, - pgx.QueryExecModeCacheDescribe, - pgx.QueryExecModeDescribeExec, - pgx.QueryExecModeExec, - pgx.QueryExecModeSimpleProtocol, - } - testWithQueryExecModes(t, modes, f) -} +var defaultConnTestRunner pgxtest.ConnTestRunner -func testWithQueryExecModes(t *testing.T, modes []pgx.QueryExecMode, f func(t *testing.T, conn *pgx.Conn)) { - for _, mode := range modes { - t.Run(mode.String(), - func(t *testing.T) { - config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) - require.NoError(t, err) - - config.DefaultQueryExecMode = mode - conn, err := pgx.ConnectConfig(context.Background(), config) - require.NoError(t, err) - defer func() { - err := conn.Close(context.Background()) - require.NoError(t, err) - }() - - f(t, conn) - - ensureConnValid(t, conn) - }, - ) +func init() { + defaultConnTestRunner = pgxtest.DefaultConnTestRunner() + defaultConnTestRunner.CreateConfig = func(ctx context.Context, t testing.TB) *pgx.ConnConfig { + config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) + require.NoError(t, err) + return config } } @@ -84,7 +62,7 @@ func mustExec(t testing.TB, conn *pgx.Conn, sql string, arguments ...interface{} } // Do a simple query to ensure the connection is still usable -func ensureConnValid(t *testing.T, conn *pgx.Conn) { +func ensureConnValid(t testing.TB, conn *pgx.Conn) { var sum, rowCount int32 rows, err := conn.Query(context.Background(), "select generate_series(1,$1)", 10) diff --git a/pgxtest/pgxtest.go b/pgxtest/pgxtest.go new file mode 100644 index 00000000..579bcd92 --- /dev/null +++ b/pgxtest/pgxtest.go @@ -0,0 +1,88 @@ +// Package pgxtest provides utilities for testing pgx and packages that integrate with pgx. +package pgxtest + +import ( + "context" + "testing" + + "github.com/jackc/pgx/v5" +) + +// 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. +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) +} + +// DefaultConnTestRunner returns a new ConnTestRunner with all fields set to reasonable default values. +func DefaultConnTestRunner() ConnTestRunner { + return ConnTestRunner{ + CreateConfig: func(ctx context.Context, t testing.TB) *pgx.ConnConfig { + config, err := pgx.ParseConfig("") + if err != nil { + t.Fatalf("ParseConfig failed: %v", err) + } + return config + }, + AfterConnect: func(ctx context.Context, t testing.TB, conn *pgx.Conn) {}, + AfterTest: func(ctx context.Context, t testing.TB, conn *pgx.Conn) {}, + CloseConn: func(ctx context.Context, t testing.TB, conn *pgx.Conn) { + err := conn.Close(ctx) + if err != nil { + t.Errorf("Close failed: %v", err) + } + }, + } +} + +func (ctr *ConnTestRunner) RunTest(ctx context.Context, t testing.TB, f func(ctx context.Context, t testing.TB, conn *pgx.Conn)) { + config := ctr.CreateConfig(ctx, t) + conn, err := pgx.ConnectConfig(ctx, config) + if err != nil { + t.Fatalf("ConnectConfig failed: %v", err) + } + defer ctr.CloseConn(ctx, t, conn) + + ctr.AfterConnect(ctx, t, conn) + f(ctx, t, conn) + ctr.AfterTest(ctx, t, 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 RunWithQueryExecModes(ctx context.Context, t *testing.T, ctr ConnTestRunner, modes []pgx.QueryExecMode, f func(ctx context.Context, t testing.TB, conn *pgx.Conn)) { + if modes == nil { + modes = []pgx.QueryExecMode{ + pgx.QueryExecModeCacheStatement, + pgx.QueryExecModeCacheDescribe, + pgx.QueryExecModeDescribeExec, + pgx.QueryExecModeExec, + pgx.QueryExecModeSimpleProtocol, + } + } + + for _, mode := range modes { + ctrWithMode := ctr + ctrWithMode.CreateConfig = func(ctx context.Context, t testing.TB) *pgx.ConnConfig { + config := ctr.CreateConfig(ctx, t) + config.DefaultQueryExecMode = mode + return config + } + + t.Run(mode.String(), + func(t *testing.T) { + ctrWithMode.RunTest(ctx, t, f) + }, + ) + } +} diff --git a/query_test.go b/query_test.go index 8e9d3ef9..e8790bba 100644 --- a/query_test.go +++ b/query_test.go @@ -15,6 +15,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -1866,7 +1867,7 @@ func TestQueryErrorWithDisabledStatementCache(t *testing.T) { func TestConnQueryFunc(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { var actualResults []interface{} var a, b int @@ -1895,7 +1896,7 @@ func TestConnQueryFunc(t *testing.T) { func TestConnQueryFuncScanError(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { var actualResults []interface{} var a, b int @@ -1917,7 +1918,7 @@ func TestConnQueryFuncScanError(t *testing.T) { func TestConnQueryFuncAbort(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { var a, b int ct, err := conn.QueryFunc( context.Background(), diff --git a/values_test.go b/values_test.go index 15c16746..55c577f5 100644 --- a/values_test.go +++ b/values_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -18,7 +19,7 @@ import ( func TestDateTranscode(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { dates := []time.Time{ time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(1000, 1, 1, 0, 0, 0, 0, time.UTC), @@ -57,7 +58,7 @@ func TestDateTranscode(t *testing.T) { func TestTimestampTzTranscode(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local) var outputTime time.Time @@ -77,7 +78,7 @@ func TestTimestampTzTranscode(t *testing.T) { func TestJSONAndJSONBTranscode(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { for _, typename := range []string{"json", "jsonb"} { if _, ok := conn.TypeMap().TypeForName(typename); !ok { continue // No JSON/JSONB type -- must be running against old PostgreSQL @@ -109,7 +110,7 @@ func TestJSONAndJSONBTranscodeExtendedOnly(t *testing.T) { } -func testJSONString(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONString(t testing.TB, conn *pgx.Conn, typename string) { input := `{"key": "value"}` expectedOutput := map[string]string{"key": "value"} var output map[string]string @@ -125,7 +126,7 @@ func testJSONString(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJSONStringPointer(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONStringPointer(t testing.TB, conn *pgx.Conn, typename string) { input := `{"key": "value"}` expectedOutput := map[string]string{"key": "value"} var output map[string]string @@ -233,7 +234,7 @@ func testJSONStruct(t *testing.T, conn *pgx.Conn, typename string) { } } -func mustParseCIDR(t *testing.T, s string) *net.IPNet { +func mustParseCIDR(t testing.TB, s string) *net.IPNet { _, ipnet, err := net.ParseCIDR(s) if err != nil { t.Fatal(err) @@ -245,7 +246,7 @@ func mustParseCIDR(t *testing.T, s string) *net.IPNet { func TestInetCIDRTranscodeIPNet(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string value *net.IPNet @@ -296,7 +297,7 @@ func TestInetCIDRTranscodeIPNet(t *testing.T) { func TestInetCIDRTranscodeIP(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string value net.IP @@ -360,7 +361,7 @@ func TestInetCIDRTranscodeIP(t *testing.T) { func TestInetCIDRArrayTranscodeIPNet(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string value []*net.IPNet @@ -423,7 +424,7 @@ func TestInetCIDRArrayTranscodeIPNet(t *testing.T) { func TestInetCIDRArrayTranscodeIP(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string value []net.IP @@ -509,7 +510,7 @@ func TestInetCIDRArrayTranscodeIP(t *testing.T) { func TestInetCIDRTranscodeWithJustIP(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string value string @@ -555,16 +556,16 @@ func TestInetCIDRTranscodeWithJustIP(t *testing.T) { func TestArrayDecoding(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { tests := []struct { sql string query interface{} scan interface{} - assert func(*testing.T, interface{}, interface{}) + assert func(testing.TB, interface{}, interface{}) }{ { "select $1::bool[]", []bool{true, false, true}, &[]bool{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]bool))) { t.Errorf("failed to encode bool[]") } @@ -572,7 +573,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::smallint[]", []int16{2, 4, 484, 32767}, &[]int16{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]int16))) { t.Errorf("failed to encode smallint[]") } @@ -580,7 +581,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::smallint[]", []uint16{2, 4, 484, 32767}, &[]uint16{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]uint16))) { t.Errorf("failed to encode smallint[]") } @@ -588,7 +589,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::int[]", []int32{2, 4, 484}, &[]int32{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]int32))) { t.Errorf("failed to encode int[]") } @@ -596,7 +597,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::int[]", []uint32{2, 4, 484, 2147483647}, &[]uint32{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]uint32))) { t.Errorf("failed to encode int[]") } @@ -604,7 +605,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::bigint[]", []int64{2, 4, 484, 9223372036854775807}, &[]int64{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]int64))) { t.Errorf("failed to encode bigint[]") } @@ -612,7 +613,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::bigint[]", []uint64{2, 4, 484, 9223372036854775807}, &[]uint64{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]uint64))) { t.Errorf("failed to encode bigint[]") } @@ -620,7 +621,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::text[]", []string{"it's", "over", "9000!"}, &[]string{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { if !reflect.DeepEqual(query, *(scan.(*[]string))) { t.Errorf("failed to encode text[]") } @@ -628,7 +629,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::timestamptz[]", []time.Time{time.Unix(323232, 0), time.Unix(3239949334, 00)}, &[]time.Time{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { queryTimeSlice := query.([]time.Time) scanTimeSlice := *(scan.(*[]time.Time)) require.Equal(t, len(queryTimeSlice), len(scanTimeSlice)) @@ -639,7 +640,7 @@ func TestArrayDecoding(t *testing.T) { }, { "select $1::bytea[]", [][]byte{{0, 1, 2, 3}, {4, 5, 6, 7}}, &[][]byte{}, - func(t *testing.T, query, scan interface{}) { + func(t testing.TB, query, scan interface{}) { queryBytesSliceSlice := query.([][]byte) scanBytesSliceSlice := *(scan.(*[][]byte)) if len(queryBytesSliceSlice) != len(scanBytesSliceSlice) { @@ -671,7 +672,7 @@ func TestArrayDecoding(t *testing.T) { func TestEmptyArrayDecoding(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { var val []string err := conn.QueryRow(context.Background(), "select array[]::text[]").Scan(&val) @@ -716,7 +717,7 @@ func TestEmptyArrayDecoding(t *testing.T) { func TestPointerPointer(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { skipCockroachDB(t, conn, "Server auto converts ints to bigint and test relies on exact types") type allTypes struct { @@ -802,7 +803,7 @@ func TestPointerPointer(t *testing.T) { func TestPointerPointerNonZero(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { f := "foo" dest := &f @@ -819,7 +820,7 @@ func TestPointerPointerNonZero(t *testing.T) { func TestEncodeTypeRename(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { type _int int inInt := _int(1) var outInt _int @@ -979,7 +980,7 @@ func TestEncodeTypeRename(t *testing.T) { func TestRowsScanNilThenScanValue(t *testing.T) { t.Parallel() - testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) { + pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { sql := `select null as a, null as b union select 1, 2