From 83e50f21e8f637e61d91598748f7a8d2d7adac33 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 2 Apr 2022 10:35:13 -0500 Subject: [PATCH] Extract SkipCockroachDB to pgxtest --- batch_test.go | 8 ++++---- conn_test.go | 12 ++++++------ copy_from_test.go | 5 +++-- helper_test.go | 6 ------ large_objects_test.go | 7 ++++--- pgxtest/pgxtest.go | 7 +++++++ query_test.go | 12 ++++++------ tx_test.go | 5 +++-- values_test.go | 2 +- 9 files changed, 34 insertions(+), 30 deletions(-) diff --git a/batch_test.go b/batch_test.go index ffd990fc..6a7abd37 100644 --- a/batch_test.go +++ b/batch_test.go @@ -17,7 +17,7 @@ func TestConnSendBatch(t *testing.T) { t.Parallel() 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") + pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test") sql := `create temporary table ledger( id serial primary key, @@ -196,7 +196,7 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) { // Don't test simple mode with prepared statements. } 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)") + pgxtest.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 { t.Fatal(err) @@ -253,7 +253,7 @@ func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing. conn := mustConnect(t, config) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)") + pgxtest.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 { @@ -600,7 +600,7 @@ func TestConnBeginBatchDeferredError(t *testing.T) { 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)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") mustExec(t, conn, `create temporary table t ( id text primary key, diff --git a/conn_test.go b/conn_test.go index 31190d7c..a618b936 100644 --- a/conn_test.go +++ b/conn_test.go @@ -506,7 +506,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { func() { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support LISTEN / NOTIFY (https://github.com/cockroachdb/cockroach/issues/41522)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support LISTEN / NOTIFY (https://github.com/cockroachdb/cockroach/issues/41522)") }() listenerDone := make(chan bool) @@ -582,7 +582,7 @@ func TestListenNotifySelfNotification(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support LISTEN / NOTIFY (https://github.com/cockroachdb/cockroach/issues/41522)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support LISTEN / NOTIFY (https://github.com/cockroachdb/cockroach/issues/41522)") mustExec(t, conn, "listen self") @@ -617,7 +617,7 @@ func TestFatalRxError(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support pg_terminate_backend() (https://github.com/cockroachdb/cockroach/issues/35897)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support pg_terminate_backend() (https://github.com/cockroachdb/cockroach/issues/35897)") var wg sync.WaitGroup wg.Add(1) @@ -656,7 +656,7 @@ func TestFatalTxError(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support pg_terminate_backend() (https://github.com/cockroachdb/cockroach/issues/35897)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support pg_terminate_backend() (https://github.com/cockroachdb/cockroach/issues/35897)") otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer otherConn.Close(context.Background()) @@ -821,7 +821,7 @@ func TestConnInitTypeMap(t *testing.T) { func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) { 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)") + pgxtest.SkipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)") var n uint64 err := conn.QueryRow(context.Background(), "select $1::uint64", "42").Scan(&n) @@ -837,7 +837,7 @@ func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) { func TestDomainType(t *testing.T) { 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)") + pgxtest.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. diff --git a/copy_from_test.go b/copy_from_test.go index 1182cb1e..54e2e52b 100644 --- a/copy_from_test.go +++ b/copy_from_test.go @@ -10,6 +10,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/require" ) @@ -134,7 +135,7 @@ func TestConnCopyFromLarge(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Skipping due to known server issue: (https://github.com/cockroachdb/cockroach/issues/52722)") + pgxtest.SkipCockroachDB(t, conn, "Skipping due to known server issue: (https://github.com/cockroachdb/cockroach/issues/52722)") mustExec(t, conn, `create temporary table foo( a int2, @@ -416,7 +417,7 @@ func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server copy error does not fail fast") + pgxtest.SkipCockroachDB(t, conn, "Server copy error does not fail fast") mustExec(t, conn, `create temporary table foo( a bytea not null diff --git a/helper_test.go b/helper_test.go index e0f04906..461dfcab 100644 --- a/helper_test.go +++ b/helper_test.go @@ -137,9 +137,3 @@ func assertConfigsEqual(t *testing.T, expected, actual *pgx.ConnConfig, testName } } } - -func skipCockroachDB(t testing.TB, conn *pgx.Conn, msg string) { - if conn.PgConn().ParameterStatus("crdb_version") != "" { - t.Skip(msg) - } -} diff --git a/large_objects_test.go b/large_objects_test.go index f86f35e9..626809e7 100644 --- a/large_objects_test.go +++ b/large_objects_test.go @@ -9,6 +9,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxtest" ) func TestLargeObjects(t *testing.T) { @@ -22,7 +23,7 @@ func TestLargeObjects(t *testing.T) { t.Fatal(err) } - skipCockroachDB(t, conn, "Server does support large objects") + pgxtest.SkipCockroachDB(t, conn, "Server does support large objects") tx, err := conn.Begin(ctx) if err != nil { @@ -50,7 +51,7 @@ func TestLargeObjectsSimpleProtocol(t *testing.T) { t.Fatal(err) } - skipCockroachDB(t, conn, "Server does support large objects") + pgxtest.SkipCockroachDB(t, conn, "Server does support large objects") tx, err := conn.Begin(ctx) if err != nil { @@ -169,7 +170,7 @@ func TestLargeObjectsMultipleTransactions(t *testing.T) { t.Fatal(err) } - skipCockroachDB(t, conn, "Server does support large objects") + pgxtest.SkipCockroachDB(t, conn, "Server does support large objects") tx, err := conn.Begin(ctx) if err != nil { diff --git a/pgxtest/pgxtest.go b/pgxtest/pgxtest.go index 579bcd92..dec6a520 100644 --- a/pgxtest/pgxtest.go +++ b/pgxtest/pgxtest.go @@ -86,3 +86,10 @@ func RunWithQueryExecModes(ctx context.Context, t *testing.T, ctr ConnTestRunner ) } } + +// SkipCockroachDB calls Skip on t with msg if the connection is to a CockroachDB server. +func SkipCockroachDB(t testing.TB, conn *pgx.Conn, msg string) { + if conn.PgConn().ParameterStatus("crdb_version") != "" { + t.Skip(msg) + } +} diff --git a/query_test.go b/query_test.go index e8790bba..007d5256 100644 --- a/query_test.go +++ b/query_test.go @@ -269,7 +269,7 @@ func TestRowsScanDoesNotAllowScanningBinaryFormatValuesIntoString(t *testing.T) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support point type") + pgxtest.SkipCockroachDB(t, conn, "Server does not support point type") var s string @@ -477,7 +477,7 @@ func TestConnQueryDeferredError(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") mustExec(t, conn, `create temporary table t ( id text primary key, @@ -519,7 +519,7 @@ func TestConnQueryErrorWhileReturningRows(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server uses numeric instead of int") + pgxtest.SkipCockroachDB(t, conn, "Server uses numeric instead of int") for i := 0; i < 100; i++ { func() { @@ -1267,7 +1267,7 @@ func TestQueryContextErrorWhileReceivingRows(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server uses numeric instead of int") + pgxtest.SkipCockroachDB(t, conn, "Server uses numeric instead of int") ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -1789,7 +1789,7 @@ func TestConnSimpleProtocolRefusesNonUTF8ClientEncoding(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support changing client_encoding (https://www.cockroachlabs.com/docs/stable/set-vars.html)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support changing client_encoding (https://www.cockroachlabs.com/docs/stable/set-vars.html)") mustExec(t, conn, "set client_encoding to 'SQL_ASCII'") @@ -1813,7 +1813,7 @@ func TestConnSimpleProtocolRefusesNonStandardConformingStrings(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support standard_conforming_strings = off (https://github.com/cockroachdb/cockroach/issues/36215)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support standard_conforming_strings = off (https://github.com/cockroachdb/cockroach/issues/36215)") mustExec(t, conn, "set standard_conforming_strings to off") diff --git a/tx_test.go b/tx_test.go index 23d76663..d45553a2 100644 --- a/tx_test.go +++ b/tx_test.go @@ -9,6 +9,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxtest" "github.com/stretchr/testify/require" ) @@ -106,7 +107,7 @@ func TestTxCommitWhenDeferredConstraintFailure(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") + pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)") createSql := ` create temporary table foo( @@ -273,7 +274,7 @@ func TestBeginIsoLevels(t *testing.T) { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) - skipCockroachDB(t, conn, "Server always uses SERIALIZABLE isolation (https://www.cockroachlabs.com/docs/stable/demo-serializable.html)") + pgxtest.SkipCockroachDB(t, conn, "Server always uses SERIALIZABLE isolation (https://www.cockroachlabs.com/docs/stable/demo-serializable.html)") isoLevels := []pgx.TxIsoLevel{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted} for _, iso := range isoLevels { diff --git a/values_test.go b/values_test.go index 55c577f5..4282880c 100644 --- a/values_test.go +++ b/values_test.go @@ -718,7 +718,7 @@ func TestPointerPointer(t *testing.T) { t.Parallel() 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") + pgxtest.SkipCockroachDB(t, conn, "Server auto converts ints to bigint and test relies on exact types") type allTypes struct { s *string