Make pgtype test compat with CockroachDB when possible

pull/1185/head
Jack Christensen 2022-03-22 20:31:00 -05:00
parent 210ebb4a50
commit e04b35bfcb
20 changed files with 73 additions and 1 deletions

View File

@ -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)

View File

@ -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{

View File

@ -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)

View File

@ -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},

View File

@ -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)

View File

@ -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"))},

View File

@ -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 {

View File

@ -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{

View File

@ -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"),

View File

@ -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)

View File

@ -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{

View File

@ -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()

View File

@ -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},

View File

@ -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{

View File

@ -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))})

View File

@ -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)

View File

@ -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)

View File

@ -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},

View File

@ -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))},

View File

@ -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))},