From e04b35bfcb741cc853d739a88e6e6c2eab591544 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Tue, 22 Mar 2022 20:31:00 -0500 Subject: [PATCH] Make pgtype test compat with CockroachDB when possible --- pgtype/array_codec_test.go | 10 ++++++++++ pgtype/box_test.go | 2 ++ pgtype/bytea_test.go | 2 +- pgtype/circle_test.go | 2 ++ pgtype/composite_test.go | 8 ++++++++ pgtype/inet_test.go | 2 ++ pgtype/line_test.go | 2 ++ pgtype/lseg_test.go | 2 ++ pgtype/macaddr_test.go | 2 ++ pgtype/numeric_test.go | 6 ++++++ pgtype/path_test.go | 2 ++ pgtype/pgtype_test.go | 10 ++++++++++ pgtype/point_test.go | 2 ++ pgtype/polygon_test.go | 2 ++ pgtype/qchar_test.go | 2 ++ pgtype/range_codec_test.go | 8 ++++++++ pgtype/text_test.go | 4 ++++ pgtype/tid_test.go | 2 ++ pgtype/timestamp_test.go | 2 ++ pgtype/timestamptz_test.go | 2 ++ 20 files changed, 73 insertions(+), 1 deletion(-) diff --git a/pgtype/array_codec_test.go b/pgtype/array_codec_test.go index 81e564c7..0cc6d7cb 100644 --- a/pgtype/array_codec_test.go +++ b/pgtype/array_codec_test.go @@ -110,6 +110,8 @@ func TestArrayCodecDecodeValue(t *testing.T) { } func TestArrayCodecScanMultipleDimensions(t *testing.T) { + skipCockroachDB(t, "Server does not support nested arrays (https://github.com/cockroachdb/cockroach/issues/36815)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -127,6 +129,8 @@ func TestArrayCodecScanMultipleDimensions(t *testing.T) { } func TestArrayCodecScanMultipleDimensionsEmpty(t *testing.T) { + skipCockroachDB(t, "Server does not support nested arrays (https://github.com/cockroachdb/cockroach/issues/36815)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -144,6 +148,8 @@ func TestArrayCodecScanMultipleDimensionsEmpty(t *testing.T) { } func TestArrayCodecScanWrongMultipleDimensions(t *testing.T) { + skipCockroachDB(t, "Server does not support nested arrays (https://github.com/cockroachdb/cockroach/issues/36815)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -158,6 +164,8 @@ func TestArrayCodecScanWrongMultipleDimensions(t *testing.T) { } func TestArrayCodecEncodeMultipleDimensions(t *testing.T) { + skipCockroachDB(t, "Server does not support nested arrays (https://github.com/cockroachdb/cockroach/issues/36815)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -175,6 +183,8 @@ func TestArrayCodecEncodeMultipleDimensions(t *testing.T) { } func TestArrayCodecEncodeMultipleDimensionsRagged(t *testing.T) { + skipCockroachDB(t, "Server does not support nested arrays (https://github.com/cockroachdb/cockroach/issues/36815)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) diff --git a/pgtype/box_test.go b/pgtype/box_test.go index 72e37b76..173fb1f5 100644 --- a/pgtype/box_test.go +++ b/pgtype/box_test.go @@ -8,6 +8,8 @@ import ( ) func TestBoxCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support box type") + testutil.RunTranscodeTests(t, "box", []testutil.TranscodeTestCase{ { pgtype.Box{ diff --git a/pgtype/bytea_test.go b/pgtype/bytea_test.go index ae4a8760..443b73ce 100644 --- a/pgtype/bytea_test.go +++ b/pgtype/bytea_test.go @@ -119,7 +119,7 @@ func TestUndecodedBytes(t *testing.T) { ctx := context.Background() var buf []byte - err := conn.QueryRow(ctx, `select 1`).Scan((*pgtype.UndecodedBytes)(&buf)) + err := conn.QueryRow(ctx, `select 1::int4`).Scan((*pgtype.UndecodedBytes)(&buf)) require.NoError(t, err) require.Len(t, buf, 4) diff --git a/pgtype/circle_test.go b/pgtype/circle_test.go index f38d8194..b78d35ba 100644 --- a/pgtype/circle_test.go +++ b/pgtype/circle_test.go @@ -8,6 +8,8 @@ import ( ) func TestCircleTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support box type") + testutil.RunTranscodeTests(t, "circle", []testutil.TranscodeTestCase{ { pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true}, diff --git a/pgtype/composite_test.go b/pgtype/composite_test.go index d97f617b..0f112ebd 100644 --- a/pgtype/composite_test.go +++ b/pgtype/composite_test.go @@ -12,6 +12,8 @@ import ( ) func TestCompositeCodecTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support composite types (see https://github.com/cockroachdb/cockroach/issues/27792)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -90,6 +92,8 @@ func (p *point3d) ScanIndex(i int) interface{} { } func TestCompositeCodecTranscodeStruct(t *testing.T) { + skipCockroachDB(t, "Server does not support composite types (see https://github.com/cockroachdb/cockroach/issues/27792)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -125,6 +129,8 @@ create type point3d as ( } func TestCompositeCodecTranscodeStructWrapper(t *testing.T) { + skipCockroachDB(t, "Server does not support composite types (see https://github.com/cockroachdb/cockroach/issues/27792)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -164,6 +170,8 @@ create type point3d as ( } func TestCompositeCodecDecodeValue(t *testing.T) { + skipCockroachDB(t, "Server does not support composite types (see https://github.com/cockroachdb/cockroach/issues/27792)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) diff --git a/pgtype/inet_test.go b/pgtype/inet_test.go index c3f66755..249caf3f 100644 --- a/pgtype/inet_test.go +++ b/pgtype/inet_test.go @@ -35,6 +35,8 @@ func TestInetTranscode(t *testing.T) { } func TestCidrTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support cidr type (see https://github.com/cockroachdb/cockroach/issues/18846)") + testutil.RunTranscodeTests(t, "cidr", []testutil.TranscodeTestCase{ {mustParseInet(t, "0.0.0.0/32"), new(net.IPNet), isExpectedEqIPNet(mustParseInet(t, "0.0.0.0/32"))}, {mustParseInet(t, "127.0.0.1/32"), new(net.IPNet), isExpectedEqIPNet(mustParseInet(t, "127.0.0.1/32"))}, diff --git a/pgtype/line_test.go b/pgtype/line_test.go index 6c7b734b..8e3d782c 100644 --- a/pgtype/line_test.go +++ b/pgtype/line_test.go @@ -9,6 +9,8 @@ import ( ) func TestLineTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support type line") + conn := testutil.MustConnectPgx(t) defer conn.Close(context.Background()) if _, ok := conn.TypeMap().TypeForName("line"); !ok { diff --git a/pgtype/lseg_test.go b/pgtype/lseg_test.go index 51fe2adb..e754b3b2 100644 --- a/pgtype/lseg_test.go +++ b/pgtype/lseg_test.go @@ -8,6 +8,8 @@ import ( ) func TestLsegTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support type lseg") + testutil.RunTranscodeTests(t, "lseg", []testutil.TranscodeTestCase{ { pgtype.Lseg{ diff --git a/pgtype/macaddr_test.go b/pgtype/macaddr_test.go index 2ce7b007..06262876 100644 --- a/pgtype/macaddr_test.go +++ b/pgtype/macaddr_test.go @@ -26,6 +26,8 @@ func isExpectedEqHardwareAddr(a interface{}) func(interface{}) bool { } func TestMacaddrCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support type macaddr") + testutil.RunTranscodeTests(t, "macaddr", []testutil.TranscodeTestCase{ { mustParseMacaddr(t, "01:23:45:67:89:ab"), diff --git a/pgtype/numeric_test.go b/pgtype/numeric_test.go index 448cfff2..d5c60575 100644 --- a/pgtype/numeric_test.go +++ b/pgtype/numeric_test.go @@ -71,6 +71,8 @@ func mustParseNumeric(t *testing.T, src string) pgtype.Numeric { } func TestNumericCodec(t *testing.T) { + skipCockroachDB(t, "server formats numeric text format differently") + max := new(big.Int).Exp(big.NewInt(10), big.NewInt(147454), nil) max.Add(max, big.NewInt(1)) longestNumeric := pgtype.Numeric{Int: max, Exp: -16383, Valid: true} @@ -143,6 +145,8 @@ func TestNumericFloat64Valuer(t *testing.T) { } func TestNumericCodecFuzz(t *testing.T) { + skipCockroachDB(t, "server formats numeric text format differently") + r := rand.New(rand.NewSource(0)) max := &big.Int{} max.SetString("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", 10) @@ -166,6 +170,8 @@ func TestNumericCodecFuzz(t *testing.T) { } func TestNumericMarshalJSON(t *testing.T) { + skipCockroachDB(t, "server formats numeric text format differently") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) diff --git a/pgtype/path_test.go b/pgtype/path_test.go index 546f4d36..40df2bfb 100644 --- a/pgtype/path_test.go +++ b/pgtype/path_test.go @@ -27,6 +27,8 @@ func isExpectedEqPath(a interface{}) func(interface{}) bool { } func TestPathTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support type path") + testutil.RunTranscodeTests(t, "path", []testutil.TranscodeTestCase{ { pgtype.Path{ diff --git a/pgtype/pgtype_test.go b/pgtype/pgtype_test.go index afa54e7a..2ee32907 100644 --- a/pgtype/pgtype_test.go +++ b/pgtype/pgtype_test.go @@ -8,6 +8,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgtype/testutil" _ "github.com/jackc/pgx/v5/stdlib" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -66,6 +67,15 @@ func mustParseMacaddr(t testing.TB, s string) net.HardwareAddr { return addr } +func skipCockroachDB(t testing.TB, msg string) { + conn := testutil.MustConnectPgx(t) + defer testutil.MustCloseContext(t, conn) + + if conn.PgConn().ParameterStatus("crdb_version") != "" { + t.Skip(msg) + } +} + func TestTypeMapScanNilIsNoOp(t *testing.T) { m := pgtype.NewMap() diff --git a/pgtype/point_test.go b/pgtype/point_test.go index 03d948b7..62fcfc51 100644 --- a/pgtype/point_test.go +++ b/pgtype/point_test.go @@ -10,6 +10,8 @@ import ( ) func TestPointCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support type point") + testutil.RunTranscodeTests(t, "point", []testutil.TranscodeTestCase{ { pgtype.Point{P: pgtype.Vec2{1.234, 5.6789012345}, Valid: true}, diff --git a/pgtype/polygon_test.go b/pgtype/polygon_test.go index 9c7c0182..6c6fc60d 100644 --- a/pgtype/polygon_test.go +++ b/pgtype/polygon_test.go @@ -27,6 +27,8 @@ func isExpectedEqPolygon(a interface{}) func(interface{}) bool { } func TestPolygonTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support type polygon") + testutil.RunTranscodeTests(t, "polygon", []testutil.TranscodeTestCase{ { pgtype.Polygon{ diff --git a/pgtype/qchar_test.go b/pgtype/qchar_test.go index 36742f75..0bf781a4 100644 --- a/pgtype/qchar_test.go +++ b/pgtype/qchar_test.go @@ -8,6 +8,8 @@ import ( ) func TestQcharTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support qchar") + var tests []testutil.TranscodeTestCase for i := 0; i <= math.MaxUint8; i++ { tests = append(tests, testutil.TranscodeTestCase{rune(i), new(rune), isExpectedEq(rune(i))}) diff --git a/pgtype/range_codec_test.go b/pgtype/range_codec_test.go index 84a55a52..b4127769 100644 --- a/pgtype/range_codec_test.go +++ b/pgtype/range_codec_test.go @@ -10,6 +10,8 @@ import ( ) func TestRangeCodecTranscode(t *testing.T) { + skipCockroachDB(t, "Server does not support range types (see https://github.com/cockroachdb/cockroach/issues/27791)") + testutil.RunTranscodeTests(t, "int4range", []testutil.TranscodeTestCase{ { pgtype.Int4range{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Valid: true}, @@ -37,6 +39,8 @@ func TestRangeCodecTranscode(t *testing.T) { } func TestRangeCodecTranscodeCompatibleRangeElementTypes(t *testing.T) { + skipCockroachDB(t, "Server does not support range types (see https://github.com/cockroachdb/cockroach/issues/27791)") + testutil.RunTranscodeTests(t, "numrange", []testutil.TranscodeTestCase{ { pgtype.Float8range{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Valid: true}, @@ -64,6 +68,8 @@ func TestRangeCodecTranscodeCompatibleRangeElementTypes(t *testing.T) { } func TestRangeCodecScanRangeTwiceWithUnbounded(t *testing.T) { + skipCockroachDB(t, "Server does not support range types (see https://github.com/cockroachdb/cockroach/issues/27791)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) @@ -116,6 +122,8 @@ func TestRangeCodecScanRangeTwiceWithUnbounded(t *testing.T) { } func TestRangeCodecDecodeValue(t *testing.T) { + skipCockroachDB(t, "Server does not support range types (see https://github.com/cockroachdb/cockroach/issues/27791)") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) diff --git a/pgtype/text_test.go b/pgtype/text_test.go index 7a188a67..c80c404b 100644 --- a/pgtype/text_test.go +++ b/pgtype/text_test.go @@ -65,6 +65,8 @@ func TestTextCodecName(t *testing.T) { // Test fixed length char types like char(3) func TestTextCodecBPChar(t *testing.T) { + skipCockroachDB(t, "Server does not properly handle bpchar with multi-byte character") + testutil.RunTranscodeTests(t, "char(3)", []testutil.TranscodeTestCase{ { pgtype.Text{String: "a ", Valid: true}, @@ -92,6 +94,8 @@ func TestTextCodecBPChar(t *testing.T) { // // It only supports the text format. func TestTextCodecACLItem(t *testing.T) { + skipCockroachDB(t, "Server does not support type aclitem") + conn := testutil.MustConnectPgx(t) defer testutil.MustCloseContext(t, conn) diff --git a/pgtype/tid_test.go b/pgtype/tid_test.go index 4ff53151..08636aa8 100644 --- a/pgtype/tid_test.go +++ b/pgtype/tid_test.go @@ -8,6 +8,8 @@ import ( ) func TestTIDCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support type tid") + testutil.RunTranscodeTests(t, "tid", []testutil.TranscodeTestCase{ { pgtype.TID{BlockNumber: 42, OffsetNumber: 43, Valid: true}, diff --git a/pgtype/timestamp_test.go b/pgtype/timestamp_test.go index a33ce78f..764baff1 100644 --- a/pgtype/timestamp_test.go +++ b/pgtype/timestamp_test.go @@ -11,6 +11,8 @@ import ( ) func TestTimestampCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support infinite timestamps (see https://github.com/cockroachdb/cockroach/issues/41564)") + testutil.RunTranscodeTests(t, "timestamp", []testutil.TranscodeTestCase{ {time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC))}, {time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))}, diff --git a/pgtype/timestamptz_test.go b/pgtype/timestamptz_test.go index ec198fa1..678f3013 100644 --- a/pgtype/timestamptz_test.go +++ b/pgtype/timestamptz_test.go @@ -11,6 +11,8 @@ import ( ) func TestTimestamptzCodec(t *testing.T) { + skipCockroachDB(t, "Server does not support infinite timestamps (see https://github.com/cockroachdb/cockroach/issues/41564)") + testutil.RunTranscodeTests(t, "timestamptz", []testutil.TranscodeTestCase{ {time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), new(time.Time), isExpectedEqTime(time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local))}, {time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local), new(time.Time), isExpectedEqTime(time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local))},