diff --git a/pgtype/aclitem_array_test.go b/pgtype/aclitem_array_test.go index 75c672bd..951e7847 100644 --- a/pgtype/aclitem_array_test.go +++ b/pgtype/aclitem_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestAclitemArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "aclitem[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "aclitem[]", []interface{}{ &pgtype.AclitemArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/aclitem_test.go b/pgtype/aclitem_test.go index 1738025a..5389eab2 100644 --- a/pgtype/aclitem_test.go +++ b/pgtype/aclitem_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestAclitemTranscode(t *testing.T) { - testSuccessfulTranscode(t, "aclitem", []interface{}{ + testutil.TestSuccessfulTranscode(t, "aclitem", []interface{}{ pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, pgtype.Aclitem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present}, pgtype.Aclitem{Status: pgtype.Null}, diff --git a/pgtype/bool_array_test.go b/pgtype/bool_array_test.go index a526d892..87886da6 100644 --- a/pgtype/bool_array_test.go +++ b/pgtype/bool_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestBoolArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "bool[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "bool[]", []interface{}{ &pgtype.BoolArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/bool_test.go b/pgtype/bool_test.go index 412e2fd0..31f3d528 100644 --- a/pgtype/bool_test.go +++ b/pgtype/bool_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestBoolTranscode(t *testing.T) { - testSuccessfulTranscode(t, "bool", []interface{}{ + testutil.TestSuccessfulTranscode(t, "bool", []interface{}{ pgtype.Bool{Bool: false, Status: pgtype.Present}, pgtype.Bool{Bool: true, Status: pgtype.Present}, pgtype.Bool{Bool: false, Status: pgtype.Null}, diff --git a/pgtype/box_test.go b/pgtype/box_test.go index 00732973..f26cda68 100644 --- a/pgtype/box_test.go +++ b/pgtype/box_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestBoxTranscode(t *testing.T) { - testSuccessfulTranscode(t, "box", []interface{}{ + testutil.TestSuccessfulTranscode(t, "box", []interface{}{ &pgtype.Box{ P: [2]pgtype.Vec2{{7.1, 5.234}, {3.14, 1.678}}, Status: pgtype.Present, @@ -21,10 +22,10 @@ func TestBoxTranscode(t *testing.T) { } func TestBoxNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select '3.14, 1.678, 7.1, 5.234'::box", - value: &pgtype.Box{ + SQL: "select '3.14, 1.678, 7.1, 5.234'::box", + Value: &pgtype.Box{ P: [2]pgtype.Vec2{{7.1, 5.234}, {3.14, 1.678}}, Status: pgtype.Present, }, diff --git a/pgtype/bytea_array_test.go b/pgtype/bytea_array_test.go index 22c6478b..451c2461 100644 --- a/pgtype/bytea_array_test.go +++ b/pgtype/bytea_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestByteaArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "bytea[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "bytea[]", []interface{}{ &pgtype.ByteaArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/bytea_test.go b/pgtype/bytea_test.go index e21296c6..7d32e294 100644 --- a/pgtype/bytea_test.go +++ b/pgtype/bytea_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestByteaTranscode(t *testing.T) { - testSuccessfulTranscode(t, "bytea", []interface{}{ + testutil.TestSuccessfulTranscode(t, "bytea", []interface{}{ pgtype.Bytea{Bytes: []byte{1, 2, 3}, Status: pgtype.Present}, pgtype.Bytea{Bytes: []byte{}, Status: pgtype.Present}, pgtype.Bytea{Bytes: nil, Status: pgtype.Null}, diff --git a/pgtype/cid_test.go b/pgtype/cid_test.go index 210573f6..385b8cac 100644 --- a/pgtype/cid_test.go +++ b/pgtype/cid_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestCidTranscode(t *testing.T) { @@ -17,13 +18,13 @@ func TestCidTranscode(t *testing.T) { return reflect.DeepEqual(a, b) } - testPgxSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) + testutil.TestPgxSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) // No direct conversion from int to cid, convert through text - testPgxSimpleProtocolSuccessfulTranscodeEqFunc(t, "text::"+pgTypeName, values, eqFunc) + testutil.TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t, "text::"+pgTypeName, values, eqFunc) for _, driverName := range []string{"github.com/lib/pq", "github.com/jackc/pgx/stdlib"} { - testDatabaseSQLSuccessfulTranscodeEqFunc(t, driverName, pgTypeName, values, eqFunc) + testutil.TestDatabaseSQLSuccessfulTranscodeEqFunc(t, driverName, pgTypeName, values, eqFunc) } } diff --git a/pgtype/cidr_array_test.go b/pgtype/cidr_array_test.go index ec105914..1ebe5195 100644 --- a/pgtype/cidr_array_test.go +++ b/pgtype/cidr_array_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestCidrArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "cidr[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "cidr[]", []interface{}{ &pgtype.CidrArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/circle_test.go b/pgtype/circle_test.go index 9746dd74..2747d4f5 100644 --- a/pgtype/circle_test.go +++ b/pgtype/circle_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestCircleTranscode(t *testing.T) { - testSuccessfulTranscode(t, "circle", []interface{}{ + testutil.TestSuccessfulTranscode(t, "circle", []interface{}{ &pgtype.Circle{P: pgtype.Vec2{1.234, 5.6789}, R: 3.5, Status: pgtype.Present}, &pgtype.Circle{P: pgtype.Vec2{-1.234, -5.6789}, R: 12.9, Status: pgtype.Present}, &pgtype.Circle{Status: pgtype.Null}, diff --git a/pgtype/date_array_test.go b/pgtype/date_array_test.go index a05f4254..74ebfbbe 100644 --- a/pgtype/date_array_test.go +++ b/pgtype/date_array_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestDateArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "date[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "date[]", []interface{}{ &pgtype.DateArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/date_test.go b/pgtype/date_test.go index 1832b5b4..d1493f5e 100644 --- a/pgtype/date_test.go +++ b/pgtype/date_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestDateTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "date", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "date", []interface{}{ pgtype.Date{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, pgtype.Date{Time: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, pgtype.Date{Time: time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, diff --git a/pgtype/daterange_test.go b/pgtype/daterange_test.go index 8501cc7e..7dfae0f4 100644 --- a/pgtype/daterange_test.go +++ b/pgtype/daterange_test.go @@ -5,10 +5,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestDaterangeTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "daterange", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "daterange", []interface{}{ pgtype.Daterange{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Status: pgtype.Present}, pgtype.Daterange{ Lower: pgtype.Date{Time: time.Date(1990, 12, 31, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, @@ -40,10 +41,10 @@ func TestDaterangeTranscode(t *testing.T) { } func TestDaterangeNormalize(t *testing.T) { - testSuccessfulNormalizeEqFunc(t, []normalizeTest{ + testutil.TestSuccessfulNormalizeEqFunc(t, []testutil.NormalizeTest{ { - sql: "select daterange('2010-01-01', '2010-01-11', '(]')", - value: pgtype.Daterange{ + SQL: "select daterange('2010-01-01', '2010-01-11', '(]')", + Value: pgtype.Daterange{ Lower: pgtype.Date{Time: time.Date(2010, 1, 2, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, Upper: pgtype.Date{Time: time.Date(2010, 1, 12, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, LowerType: pgtype.Inclusive, diff --git a/pgtype/float4_array_test.go b/pgtype/float4_array_test.go index 06a1d2e0..6d6a4f30 100644 --- a/pgtype/float4_array_test.go +++ b/pgtype/float4_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestFloat4ArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "float4[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "float4[]", []interface{}{ &pgtype.Float4Array{ Elements: nil, Dimensions: nil, diff --git a/pgtype/float4_test.go b/pgtype/float4_test.go index ea60cd3a..57f4bc34 100644 --- a/pgtype/float4_test.go +++ b/pgtype/float4_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestFloat4Transcode(t *testing.T) { - testSuccessfulTranscode(t, "float4", []interface{}{ + testutil.TestSuccessfulTranscode(t, "float4", []interface{}{ pgtype.Float4{Float: -1, Status: pgtype.Present}, pgtype.Float4{Float: 0, Status: pgtype.Present}, pgtype.Float4{Float: 0.00001, Status: pgtype.Present}, diff --git a/pgtype/float8_array_test.go b/pgtype/float8_array_test.go index 635e249a..56801e80 100644 --- a/pgtype/float8_array_test.go +++ b/pgtype/float8_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestFloat8ArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "float8[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "float8[]", []interface{}{ &pgtype.Float8Array{ Elements: nil, Dimensions: nil, diff --git a/pgtype/float8_test.go b/pgtype/float8_test.go index 724e9350..b7527b86 100644 --- a/pgtype/float8_test.go +++ b/pgtype/float8_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestFloat8Transcode(t *testing.T) { - testSuccessfulTranscode(t, "float8", []interface{}{ + testutil.TestSuccessfulTranscode(t, "float8", []interface{}{ pgtype.Float8{Float: -1, Status: pgtype.Present}, pgtype.Float8{Float: 0, Status: pgtype.Present}, pgtype.Float8{Float: 0.00001, Status: pgtype.Present}, diff --git a/pgtype/hstore_array_test.go b/pgtype/hstore_array_test.go index e23c7b3b..d26497b1 100644 --- a/pgtype/hstore_array_test.go +++ b/pgtype/hstore_array_test.go @@ -6,11 +6,12 @@ import ( "github.com/jackc/pgx" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestHstoreArrayTranscode(t *testing.T) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := testutil.MustConnectPgx(t) + defer testutil.MustClose(t, conn) text := func(s string) pgtype.Text { return pgtype.Text{String: s, Status: pgtype.Present} @@ -69,7 +70,7 @@ func TestHstoreArrayTranscode(t *testing.T) { for _, fc := range formats { ps.FieldDescriptions[0].FormatCode = fc.formatCode - vEncoder := forceEncoder(src, fc.formatCode) + vEncoder := testutil.ForceEncoder(src, fc.formatCode) if vEncoder == nil { t.Logf("%#v does not implement %v", src, fc.name) continue diff --git a/pgtype/hstore_test.go b/pgtype/hstore_test.go index fbe8dee5..502a8df0 100644 --- a/pgtype/hstore_test.go +++ b/pgtype/hstore_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestHstoreTranscode(t *testing.T) { @@ -44,7 +45,7 @@ func TestHstoreTranscode(t *testing.T) { values = append(values, pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text(s)}, Status: pgtype.Present}) // is key } - testSuccessfulTranscodeEqFunc(t, "hstore", values, func(ai, bi interface{}) bool { + testutil.TestSuccessfulTranscodeEqFunc(t, "hstore", values, func(ai, bi interface{}) bool { a := ai.(pgtype.Hstore) b := bi.(pgtype.Hstore) diff --git a/pgtype/inet_array_test.go b/pgtype/inet_array_test.go index fe22285d..c0465922 100644 --- a/pgtype/inet_array_test.go +++ b/pgtype/inet_array_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInetArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "inet[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "inet[]", []interface{}{ &pgtype.InetArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/inet_test.go b/pgtype/inet_test.go index 16035fca..532e9abe 100644 --- a/pgtype/inet_test.go +++ b/pgtype/inet_test.go @@ -6,11 +6,12 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInetTranscode(t *testing.T) { for _, pgTypeName := range []string{"inet", "cidr"} { - testSuccessfulTranscode(t, pgTypeName, []interface{}{ + testutil.TestSuccessfulTranscode(t, pgTypeName, []interface{}{ pgtype.Inet{IPNet: mustParseCidr(t, "0.0.0.0/32"), Status: pgtype.Present}, pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}, pgtype.Inet{IPNet: mustParseCidr(t, "12.34.56.0/32"), Status: pgtype.Present}, diff --git a/pgtype/int2_array_test.go b/pgtype/int2_array_test.go index 8af4523d..0adc1aef 100644 --- a/pgtype/int2_array_test.go +++ b/pgtype/int2_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt2ArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "int2[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int2[]", []interface{}{ &pgtype.Int2Array{ Elements: nil, Dimensions: nil, diff --git a/pgtype/int2_test.go b/pgtype/int2_test.go index 2bd8e016..d81405a6 100644 --- a/pgtype/int2_test.go +++ b/pgtype/int2_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt2Transcode(t *testing.T) { - testSuccessfulTranscode(t, "int2", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int2", []interface{}{ pgtype.Int2{Int: math.MinInt16, Status: pgtype.Present}, pgtype.Int2{Int: -1, Status: pgtype.Present}, pgtype.Int2{Int: 0, Status: pgtype.Present}, diff --git a/pgtype/int4_array_test.go b/pgtype/int4_array_test.go index 111cb56b..6fad18bb 100644 --- a/pgtype/int4_array_test.go +++ b/pgtype/int4_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt4ArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "int4[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int4[]", []interface{}{ &pgtype.Int4Array{ Elements: nil, Dimensions: nil, diff --git a/pgtype/int4_test.go b/pgtype/int4_test.go index 3e000182..1354b47a 100644 --- a/pgtype/int4_test.go +++ b/pgtype/int4_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt4Transcode(t *testing.T) { - testSuccessfulTranscode(t, "int4", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int4", []interface{}{ pgtype.Int4{Int: math.MinInt32, Status: pgtype.Present}, pgtype.Int4{Int: -1, Status: pgtype.Present}, pgtype.Int4{Int: 0, Status: pgtype.Present}, diff --git a/pgtype/int4range_test.go b/pgtype/int4range_test.go index c96fe9cd..74a91e59 100644 --- a/pgtype/int4range_test.go +++ b/pgtype/int4range_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt4rangeTranscode(t *testing.T) { - testSuccessfulTranscode(t, "int4range", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int4range", []interface{}{ pgtype.Int4range{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Status: pgtype.Present}, pgtype.Int4range{Lower: pgtype.Int4{Int: 1, Status: pgtype.Present}, Upper: pgtype.Int4{Int: 10, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, pgtype.Int4range{Lower: pgtype.Int4{Int: -42, Status: pgtype.Present}, Upper: pgtype.Int4{Int: -5, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, @@ -16,10 +17,10 @@ func TestInt4rangeTranscode(t *testing.T) { } func TestInt4rangeNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select int4range(1, 10, '(]')", - value: pgtype.Int4range{Lower: pgtype.Int4{Int: 2, Status: pgtype.Present}, Upper: pgtype.Int4{Int: 11, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, + SQL: "select int4range(1, 10, '(]')", + Value: pgtype.Int4range{Lower: pgtype.Int4{Int: 2, Status: pgtype.Present}, Upper: pgtype.Int4{Int: 11, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, }, }) } diff --git a/pgtype/int8_array_test.go b/pgtype/int8_array_test.go index 349a1f7e..4f5c4f9a 100644 --- a/pgtype/int8_array_test.go +++ b/pgtype/int8_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt8ArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "int8[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int8[]", []interface{}{ &pgtype.Int8Array{ Elements: nil, Dimensions: nil, diff --git a/pgtype/int8_test.go b/pgtype/int8_test.go index e1fe69fb..d6752205 100644 --- a/pgtype/int8_test.go +++ b/pgtype/int8_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt8Transcode(t *testing.T) { - testSuccessfulTranscode(t, "int8", []interface{}{ + testutil.TestSuccessfulTranscode(t, "int8", []interface{}{ pgtype.Int8{Int: math.MinInt64, Status: pgtype.Present}, pgtype.Int8{Int: -1, Status: pgtype.Present}, pgtype.Int8{Int: 0, Status: pgtype.Present}, diff --git a/pgtype/int8range_test.go b/pgtype/int8range_test.go index 1b3e594c..703f476e 100644 --- a/pgtype/int8range_test.go +++ b/pgtype/int8range_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestInt8rangeTranscode(t *testing.T) { - testSuccessfulTranscode(t, "Int8range", []interface{}{ + testutil.TestSuccessfulTranscode(t, "Int8range", []interface{}{ pgtype.Int8range{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Status: pgtype.Present}, pgtype.Int8range{Lower: pgtype.Int8{Int: 1, Status: pgtype.Present}, Upper: pgtype.Int8{Int: 10, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, pgtype.Int8range{Lower: pgtype.Int8{Int: -42, Status: pgtype.Present}, Upper: pgtype.Int8{Int: -5, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, @@ -16,10 +17,10 @@ func TestInt8rangeTranscode(t *testing.T) { } func TestInt8rangeNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select Int8range(1, 10, '(]')", - value: pgtype.Int8range{Lower: pgtype.Int8{Int: 2, Status: pgtype.Present}, Upper: pgtype.Int8{Int: 11, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, + SQL: "select Int8range(1, 10, '(]')", + Value: pgtype.Int8range{Lower: pgtype.Int8{Int: 2, Status: pgtype.Present}, Upper: pgtype.Int8{Int: 11, Status: pgtype.Present}, LowerType: pgtype.Inclusive, UpperType: pgtype.Exclusive, Status: pgtype.Present}, }, }) } diff --git a/pgtype/interval_test.go b/pgtype/interval_test.go index db9614ef..28e77e0a 100644 --- a/pgtype/interval_test.go +++ b/pgtype/interval_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestIntervalTranscode(t *testing.T) { - testSuccessfulTranscode(t, "interval", []interface{}{ + testutil.TestSuccessfulTranscode(t, "interval", []interface{}{ pgtype.Interval{Microseconds: 1, Status: pgtype.Present}, pgtype.Interval{Microseconds: 1000000, Status: pgtype.Present}, pgtype.Interval{Microseconds: 1000001, Status: pgtype.Present}, @@ -29,34 +30,34 @@ func TestIntervalTranscode(t *testing.T) { } func TestIntervalNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select '1 second'::interval", - value: pgtype.Interval{Microseconds: 1000000, Status: pgtype.Present}, + SQL: "select '1 second'::interval", + Value: pgtype.Interval{Microseconds: 1000000, Status: pgtype.Present}, }, { - sql: "select '1.000001 second'::interval", - value: pgtype.Interval{Microseconds: 1000001, Status: pgtype.Present}, + SQL: "select '1.000001 second'::interval", + Value: pgtype.Interval{Microseconds: 1000001, Status: pgtype.Present}, }, { - sql: "select '34223 hours'::interval", - value: pgtype.Interval{Microseconds: 123202800000000, Status: pgtype.Present}, + SQL: "select '34223 hours'::interval", + Value: pgtype.Interval{Microseconds: 123202800000000, Status: pgtype.Present}, }, { - sql: "select '1 day'::interval", - value: pgtype.Interval{Days: 1, Status: pgtype.Present}, + SQL: "select '1 day'::interval", + Value: pgtype.Interval{Days: 1, Status: pgtype.Present}, }, { - sql: "select '1 month'::interval", - value: pgtype.Interval{Months: 1, Status: pgtype.Present}, + SQL: "select '1 month'::interval", + Value: pgtype.Interval{Months: 1, Status: pgtype.Present}, }, { - sql: "select '1 year'::interval", - value: pgtype.Interval{Months: 12, Status: pgtype.Present}, + SQL: "select '1 year'::interval", + Value: pgtype.Interval{Months: 12, Status: pgtype.Present}, }, { - sql: "select '-13 mon'::interval", - value: pgtype.Interval{Months: -13, Status: pgtype.Present}, + SQL: "select '-13 mon'::interval", + Value: pgtype.Interval{Months: -13, Status: pgtype.Present}, }, }) } diff --git a/pgtype/json_test.go b/pgtype/json_test.go index b0aa8c9b..6d7cccfd 100644 --- a/pgtype/json_test.go +++ b/pgtype/json_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestJsonTranscode(t *testing.T) { - testSuccessfulTranscode(t, "json", []interface{}{ + testutil.TestSuccessfulTranscode(t, "json", []interface{}{ pgtype.Json{Bytes: []byte("{}"), Status: pgtype.Present}, pgtype.Json{Bytes: []byte("null"), Status: pgtype.Present}, pgtype.Json{Bytes: []byte("42"), Status: pgtype.Present}, diff --git a/pgtype/jsonb_test.go b/pgtype/jsonb_test.go index 91637eb8..37c11858 100644 --- a/pgtype/jsonb_test.go +++ b/pgtype/jsonb_test.go @@ -6,16 +6,17 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestJsonbTranscode(t *testing.T) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := testutil.MustConnectPgx(t) + defer testutil.MustClose(t, conn) if _, ok := conn.ConnInfo.DataTypeForName("jsonb"); !ok { t.Skip("Skipping due to no jsonb type") } - testSuccessfulTranscode(t, "jsonb", []interface{}{ + testutil.TestSuccessfulTranscode(t, "jsonb", []interface{}{ pgtype.Jsonb{Bytes: []byte("{}"), Status: pgtype.Present}, pgtype.Jsonb{Bytes: []byte("null"), Status: pgtype.Present}, pgtype.Jsonb{Bytes: []byte("42"), Status: pgtype.Present}, diff --git a/pgtype/line_test.go b/pgtype/line_test.go index 995eaad5..09e48019 100644 --- a/pgtype/line_test.go +++ b/pgtype/line_test.go @@ -5,15 +5,16 @@ import ( version "github.com/hashicorp/go-version" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestLineTranscode(t *testing.T) { - conn := mustConnectPgx(t) + conn := testutil.MustConnectPgx(t) serverVersion, err := version.NewVersion(conn.RuntimeParams["server_version"]) if err != nil { t.Fatalf("cannot get server version: %v", err) } - mustClose(t, conn) + testutil.MustClose(t, conn) minVersion := version.Must(version.NewVersion("9.4")) @@ -21,7 +22,7 @@ func TestLineTranscode(t *testing.T) { t.Skipf("Skipping line test for server version %v", serverVersion) } - testSuccessfulTranscode(t, "line", []interface{}{ + testutil.TestSuccessfulTranscode(t, "line", []interface{}{ &pgtype.Line{ A: 1.23, B: 4.56, C: 7.89, Status: pgtype.Present, diff --git a/pgtype/lseg_test.go b/pgtype/lseg_test.go index 5f041263..bd394e3c 100644 --- a/pgtype/lseg_test.go +++ b/pgtype/lseg_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestLsegTranscode(t *testing.T) { - testSuccessfulTranscode(t, "lseg", []interface{}{ + testutil.TestSuccessfulTranscode(t, "lseg", []interface{}{ &pgtype.Lseg{ P: [2]pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}}, Status: pgtype.Present, diff --git a/pgtype/macaddr_test.go b/pgtype/macaddr_test.go index 6c7b8b89..c2542da3 100644 --- a/pgtype/macaddr_test.go +++ b/pgtype/macaddr_test.go @@ -7,10 +7,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestMacaddrTranscode(t *testing.T) { - testSuccessfulTranscode(t, "macaddr", []interface{}{ + testutil.TestSuccessfulTranscode(t, "macaddr", []interface{}{ pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present}, pgtype.Macaddr{Status: pgtype.Null}, }) diff --git a/pgtype/name_test.go b/pgtype/name_test.go index 81a766b8..348f8d39 100644 --- a/pgtype/name_test.go +++ b/pgtype/name_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestNameTranscode(t *testing.T) { - testSuccessfulTranscode(t, "name", []interface{}{ + testutil.TestSuccessfulTranscode(t, "name", []interface{}{ pgtype.Name{String: "", Status: pgtype.Present}, pgtype.Name{String: "foo", Status: pgtype.Present}, pgtype.Name{Status: pgtype.Null}, diff --git a/pgtype/numeric_array_test.go b/pgtype/numeric_array_test.go index af2e8e51..25531840 100644 --- a/pgtype/numeric_array_test.go +++ b/pgtype/numeric_array_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestNumericArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "numeric[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "numeric[]", []interface{}{ &pgtype.NumericArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/numeric_test.go b/pgtype/numeric_test.go index 93aa8866..d68a9347 100644 --- a/pgtype/numeric_test.go +++ b/pgtype/numeric_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) // For test purposes only. Note that it does not normalize values. e.g. (Int: 1, Exp: 3) will not equal (Int: 1000, Exp: 0) @@ -45,66 +46,66 @@ func mustParseBigInt(t *testing.T, src string) *big.Int { } func TestNumericNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select '0'::numeric", - value: pgtype.Numeric{Int: big.NewInt(0), Exp: 0, Status: pgtype.Present}, + SQL: "select '0'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(0), Exp: 0, Status: pgtype.Present}, }, { - sql: "select '1'::numeric", - value: pgtype.Numeric{Int: big.NewInt(1), Exp: 0, Status: pgtype.Present}, + SQL: "select '1'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(1), Exp: 0, Status: pgtype.Present}, }, { - sql: "select '10.00'::numeric", - value: pgtype.Numeric{Int: big.NewInt(1000), Exp: -2, Status: pgtype.Present}, + SQL: "select '10.00'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(1000), Exp: -2, Status: pgtype.Present}, }, { - sql: "select '1e-3'::numeric", - value: pgtype.Numeric{Int: big.NewInt(1), Exp: -3, Status: pgtype.Present}, + SQL: "select '1e-3'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(1), Exp: -3, Status: pgtype.Present}, }, { - sql: "select '-1'::numeric", - value: pgtype.Numeric{Int: big.NewInt(-1), Exp: 0, Status: pgtype.Present}, + SQL: "select '-1'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(-1), Exp: 0, Status: pgtype.Present}, }, { - sql: "select '10000'::numeric", - value: pgtype.Numeric{Int: big.NewInt(1), Exp: 4, Status: pgtype.Present}, + SQL: "select '10000'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(1), Exp: 4, Status: pgtype.Present}, }, { - sql: "select '3.14'::numeric", - value: pgtype.Numeric{Int: big.NewInt(314), Exp: -2, Status: pgtype.Present}, + SQL: "select '3.14'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(314), Exp: -2, Status: pgtype.Present}, }, { - sql: "select '1.1'::numeric", - value: pgtype.Numeric{Int: big.NewInt(11), Exp: -1, Status: pgtype.Present}, + SQL: "select '1.1'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(11), Exp: -1, Status: pgtype.Present}, }, { - sql: "select '100010001'::numeric", - value: pgtype.Numeric{Int: big.NewInt(100010001), Exp: 0, Status: pgtype.Present}, + SQL: "select '100010001'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(100010001), Exp: 0, Status: pgtype.Present}, }, { - sql: "select '100010001.0001'::numeric", - value: pgtype.Numeric{Int: big.NewInt(1000100010001), Exp: -4, Status: pgtype.Present}, + SQL: "select '100010001.0001'::numeric", + Value: pgtype.Numeric{Int: big.NewInt(1000100010001), Exp: -4, Status: pgtype.Present}, }, { - sql: "select '4237234789234789289347892374324872138321894178943189043890124832108934.43219085471578891547854892438945012347981'::numeric", - value: pgtype.Numeric{ + SQL: "select '4237234789234789289347892374324872138321894178943189043890124832108934.43219085471578891547854892438945012347981'::numeric", + Value: pgtype.Numeric{ Int: mustParseBigInt(t, "423723478923478928934789237432487213832189417894318904389012483210893443219085471578891547854892438945012347981"), Exp: -41, Status: pgtype.Present, }, }, { - sql: "select '0.8925092023480223478923478978978937897879595901237890234789243679037419057877231734823098432903527585734549035904590854890345905434578345789347890402348952348905890489054234237489234987723894789234'::numeric", - value: pgtype.Numeric{ + SQL: "select '0.8925092023480223478923478978978937897879595901237890234789243679037419057877231734823098432903527585734549035904590854890345905434578345789347890402348952348905890489054234237489234987723894789234'::numeric", + Value: pgtype.Numeric{ Int: mustParseBigInt(t, "8925092023480223478923478978978937897879595901237890234789243679037419057877231734823098432903527585734549035904590854890345905434578345789347890402348952348905890489054234237489234987723894789234"), Exp: -196, Status: pgtype.Present, }, }, { - sql: "select '0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000123'::numeric", - value: pgtype.Numeric{ + SQL: "select '0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000123'::numeric", + Value: pgtype.Numeric{ Int: mustParseBigInt(t, "123"), Exp: -186, Status: pgtype.Present, @@ -114,7 +115,7 @@ func TestNumericNormalize(t *testing.T) { } func TestNumericTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "numeric", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "numeric", []interface{}{ &pgtype.Numeric{Int: big.NewInt(0), Exp: 0, Status: pgtype.Present}, &pgtype.Numeric{Int: big.NewInt(1), Exp: 0, Status: pgtype.Present}, &pgtype.Numeric{Int: big.NewInt(-1), Exp: 0, Status: pgtype.Present}, @@ -172,7 +173,7 @@ func TestNumericTranscodeFuzz(t *testing.T) { } } - testSuccessfulTranscodeEqFunc(t, "numeric", values, + testutil.TestSuccessfulTranscodeEqFunc(t, "numeric", values, func(aa, bb interface{}) bool { a := aa.(pgtype.Numeric) b := bb.(pgtype.Numeric) diff --git a/pgtype/numrange_test.go b/pgtype/numrange_test.go index 81202362..81e73c38 100644 --- a/pgtype/numrange_test.go +++ b/pgtype/numrange_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestNumrangeTranscode(t *testing.T) { - testSuccessfulTranscode(t, "numrange", []interface{}{ + testutil.TestSuccessfulTranscode(t, "numrange", []interface{}{ pgtype.Numrange{ LowerType: pgtype.Empty, UpperType: pgtype.Empty, diff --git a/pgtype/oid_value_test.go b/pgtype/oid_value_test.go index 21dd6f9d..d3412159 100644 --- a/pgtype/oid_value_test.go +++ b/pgtype/oid_value_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestOidValueTranscode(t *testing.T) { - testSuccessfulTranscode(t, "oid", []interface{}{ + testutil.TestSuccessfulTranscode(t, "oid", []interface{}{ pgtype.OidValue{Uint: 42, Status: pgtype.Present}, pgtype.OidValue{Status: pgtype.Null}, }) diff --git a/pgtype/path_test.go b/pgtype/path_test.go index 4e5f7f62..d213a1b4 100644 --- a/pgtype/path_test.go +++ b/pgtype/path_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestPathTranscode(t *testing.T) { - testSuccessfulTranscode(t, "path", []interface{}{ + testutil.TestSuccessfulTranscode(t, "path", []interface{}{ &pgtype.Path{ P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}}, Closed: false, diff --git a/pgtype/pgtype_test.go b/pgtype/pgtype_test.go index f486f077..716e063d 100644 --- a/pgtype/pgtype_test.go +++ b/pgtype/pgtype_test.go @@ -1,17 +1,9 @@ package pgtype_test import ( - "context" - "database/sql" - "fmt" - "io" "net" - "os" - "reflect" "testing" - "github.com/jackc/pgx" - "github.com/jackc/pgx/pgtype" _ "github.com/jackc/pgx/stdlib" _ "github.com/lib/pq" ) @@ -28,48 +20,6 @@ type _float32Slice []float32 type _float64Slice []float64 type _byteSlice []byte -func mustConnectDatabaseSQL(t testing.TB, driverName string) *sql.DB { - var sqlDriverName string - switch driverName { - case "github.com/lib/pq": - sqlDriverName = "postgres" - case "github.com/jackc/pgx/stdlib": - sqlDriverName = "pgx" - default: - t.Fatalf("Unknown driver %v", driverName) - } - - db, err := sql.Open(sqlDriverName, os.Getenv("DATABASE_URL")) - if err != nil { - t.Fatal(err) - } - - return db -} - -func mustConnectPgx(t testing.TB) *pgx.Conn { - config, err := pgx.ParseURI(os.Getenv("DATABASE_URL")) - if err != nil { - t.Fatal(err) - } - - conn, err := pgx.Connect(config) - if err != nil { - t.Fatal(err) - } - - return conn -} - -func mustClose(t testing.TB, conn interface { - Close() error -}) { - err := conn.Close() - if err != nil { - t.Fatal(err) - } -} - func mustParseCidr(t testing.TB, s string) *net.IPNet { _, ipnet, err := net.ParseCIDR(s) if err != nil { @@ -87,244 +37,3 @@ func mustParseMacaddr(t testing.TB, s string) net.HardwareAddr { return addr } - -type forceTextEncoder struct { - e pgtype.TextEncoder -} - -func (f forceTextEncoder) EncodeText(ci *pgtype.ConnInfo, w io.Writer) (bool, error) { - return f.e.EncodeText(ci, w) -} - -type forceBinaryEncoder struct { - e pgtype.BinaryEncoder -} - -func (f forceBinaryEncoder) EncodeBinary(ci *pgtype.ConnInfo, w io.Writer) (bool, error) { - return f.e.EncodeBinary(ci, w) -} - -func forceEncoder(e interface{}, formatCode int16) interface{} { - switch formatCode { - case pgx.TextFormatCode: - if e, ok := e.(pgtype.TextEncoder); ok { - return forceTextEncoder{e: e} - } - case pgx.BinaryFormatCode: - if e, ok := e.(pgtype.BinaryEncoder); ok { - return forceBinaryEncoder{e: e.(pgtype.BinaryEncoder)} - } - } - return nil -} - -func testSuccessfulTranscode(t testing.TB, pgTypeName string, values []interface{}) { - testSuccessfulTranscodeEqFunc(t, pgTypeName, values, func(a, b interface{}) bool { - return reflect.DeepEqual(a, b) - }) -} - -func testSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - testPgxSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) - testPgxSimpleProtocolSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) - for _, driverName := range []string{"github.com/lib/pq", "github.com/jackc/pgx/stdlib"} { - testDatabaseSQLSuccessfulTranscodeEqFunc(t, driverName, pgTypeName, values, eqFunc) - } -} - -func testPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) - - ps, err := conn.Prepare("test", fmt.Sprintf("select $1::%s", pgTypeName)) - if err != nil { - t.Fatal(err) - } - - formats := []struct { - name string - formatCode int16 - }{ - {name: "TextFormat", formatCode: pgx.TextFormatCode}, - {name: "BinaryFormat", formatCode: pgx.BinaryFormatCode}, - } - - for i, v := range values { - for _, fc := range formats { - ps.FieldDescriptions[0].FormatCode = fc.formatCode - vEncoder := forceEncoder(v, fc.formatCode) - if vEncoder == nil { - t.Logf("Skipping: %#v does not implement %v", v, fc.name) - continue - } - // Derefence value if it is a pointer - derefV := v - refVal := reflect.ValueOf(v) - if refVal.Kind() == reflect.Ptr { - derefV = refVal.Elem().Interface() - } - - result := reflect.New(reflect.TypeOf(derefV)) - err := conn.QueryRow("test", forceEncoder(v, fc.formatCode)).Scan(result.Interface()) - if err != nil { - t.Errorf("%v %d: %v", fc.name, i, err) - } - - if !eqFunc(result.Elem().Interface(), derefV) { - t.Errorf("%v %d: expected %v, got %v", fc.name, i, derefV, result.Elem().Interface()) - } - } - } -} - -func testPgxSimpleProtocolSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) - - for i, v := range values { - // Derefence value if it is a pointer - derefV := v - refVal := reflect.ValueOf(v) - if refVal.Kind() == reflect.Ptr { - derefV = refVal.Elem().Interface() - } - - result := reflect.New(reflect.TypeOf(derefV)) - err := conn.QueryRowEx( - context.Background(), - fmt.Sprintf("select ($1)::%s", pgTypeName), - &pgx.QueryExOptions{SimpleProtocol: true}, - v, - ).Scan(result.Interface()) - if err != nil { - t.Errorf("Simple protocol %d: %v", i, err) - } - - if !eqFunc(result.Elem().Interface(), derefV) { - t.Errorf("Simple protocol %d: expected %v, got %v", i, derefV, result.Elem().Interface()) - } - } -} - -func testDatabaseSQLSuccessfulTranscodeEqFunc(t testing.TB, driverName, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectDatabaseSQL(t, driverName) - defer mustClose(t, conn) - - ps, err := conn.Prepare(fmt.Sprintf("select $1::%s", pgTypeName)) - if err != nil { - t.Fatal(err) - } - - for i, v := range values { - // Derefence value if it is a pointer - derefV := v - refVal := reflect.ValueOf(v) - if refVal.Kind() == reflect.Ptr { - derefV = refVal.Elem().Interface() - } - - result := reflect.New(reflect.TypeOf(derefV)) - err := ps.QueryRow(v).Scan(result.Interface()) - if err != nil { - t.Errorf("%v %d: %v", driverName, i, err) - } - - if !eqFunc(result.Elem().Interface(), derefV) { - t.Errorf("%v %d: expected %v, got %v", driverName, i, derefV, result.Elem().Interface()) - } - } -} - -type normalizeTest struct { - sql string - value interface{} -} - -func testSuccessfulNormalize(t testing.TB, tests []normalizeTest) { - testSuccessfulNormalizeEqFunc(t, tests, func(a, b interface{}) bool { - return reflect.DeepEqual(a, b) - }) -} - -func testSuccessfulNormalizeEqFunc(t testing.TB, tests []normalizeTest, eqFunc func(a, b interface{}) bool) { - testPgxSuccessfulNormalizeEqFunc(t, tests, eqFunc) - for _, driverName := range []string{"github.com/lib/pq", "github.com/jackc/pgx/stdlib"} { - testDatabaseSQLSuccessfulNormalizeEqFunc(t, driverName, tests, eqFunc) - } -} - -func testPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []normalizeTest, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) - - formats := []struct { - name string - formatCode int16 - }{ - {name: "TextFormat", formatCode: pgx.TextFormatCode}, - {name: "BinaryFormat", formatCode: pgx.BinaryFormatCode}, - } - - for i, tt := range tests { - for _, fc := range formats { - psName := fmt.Sprintf("test%d", i) - ps, err := conn.Prepare(psName, tt.sql) - if err != nil { - t.Fatal(err) - } - - ps.FieldDescriptions[0].FormatCode = fc.formatCode - if forceEncoder(tt.value, fc.formatCode) == nil { - t.Logf("Skipping: %#v does not implement %v", tt.value, fc.name) - continue - } - // Derefence value if it is a pointer - derefV := tt.value - refVal := reflect.ValueOf(tt.value) - if refVal.Kind() == reflect.Ptr { - derefV = refVal.Elem().Interface() - } - - result := reflect.New(reflect.TypeOf(derefV)) - err = conn.QueryRow(psName).Scan(result.Interface()) - if err != nil { - t.Errorf("%v %d: %v", fc.name, i, err) - } - - if !eqFunc(result.Elem().Interface(), derefV) { - t.Errorf("%v %d: expected %v, got %v", fc.name, i, derefV, result.Elem().Interface()) - } - } - } -} - -func testDatabaseSQLSuccessfulNormalizeEqFunc(t testing.TB, driverName string, tests []normalizeTest, eqFunc func(a, b interface{}) bool) { - conn := mustConnectDatabaseSQL(t, driverName) - defer mustClose(t, conn) - - for i, tt := range tests { - ps, err := conn.Prepare(tt.sql) - if err != nil { - t.Errorf("%d. %v", i, err) - continue - } - - // Derefence value if it is a pointer - derefV := tt.value - refVal := reflect.ValueOf(tt.value) - if refVal.Kind() == reflect.Ptr { - derefV = refVal.Elem().Interface() - } - - result := reflect.New(reflect.TypeOf(derefV)) - err = ps.QueryRow().Scan(result.Interface()) - if err != nil { - t.Errorf("%v %d: %v", driverName, i, err) - } - - if !eqFunc(result.Elem().Interface(), derefV) { - t.Errorf("%v %d: expected %v, got %v", driverName, i, derefV, result.Elem().Interface()) - } - } - -} diff --git a/pgtype/point_test.go b/pgtype/point_test.go index c921f794..f46b342d 100644 --- a/pgtype/point_test.go +++ b/pgtype/point_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestPointTranscode(t *testing.T) { - testSuccessfulTranscode(t, "point", []interface{}{ + testutil.TestSuccessfulTranscode(t, "point", []interface{}{ &pgtype.Point{P: pgtype.Vec2{1.234, 5.6789}, Status: pgtype.Present}, &pgtype.Point{P: pgtype.Vec2{-1.234, -5.6789}, Status: pgtype.Present}, &pgtype.Point{Status: pgtype.Null}, diff --git a/pgtype/polygon_test.go b/pgtype/polygon_test.go index 3a7e1431..48481dc5 100644 --- a/pgtype/polygon_test.go +++ b/pgtype/polygon_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestPolygonTranscode(t *testing.T) { - testSuccessfulTranscode(t, "polygon", []interface{}{ + testutil.TestSuccessfulTranscode(t, "polygon", []interface{}{ &pgtype.Polygon{ P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}, {5.0, 3.234}}, Status: pgtype.Present, diff --git a/pgtype/qchar_test.go b/pgtype/qchar_test.go index afac5016..b810b89c 100644 --- a/pgtype/qchar_test.go +++ b/pgtype/qchar_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestQCharTranscode(t *testing.T) { - testPgxSuccessfulTranscodeEqFunc(t, `"char"`, []interface{}{ + testutil.TestPgxSuccessfulTranscodeEqFunc(t, `"char"`, []interface{}{ pgtype.QChar{Int: math.MinInt8, Status: pgtype.Present}, pgtype.QChar{Int: -1, Status: pgtype.Present}, pgtype.QChar{Int: 0, Status: pgtype.Present}, diff --git a/pgtype/record_test.go b/pgtype/record_test.go index bc6e5893..df17501f 100644 --- a/pgtype/record_test.go +++ b/pgtype/record_test.go @@ -7,11 +7,12 @@ import ( "github.com/jackc/pgx" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestRecordTranscode(t *testing.T) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := testutil.MustConnectPgx(t) + defer testutil.MustClose(t, conn) tests := []struct { sql string diff --git a/pgtype/testutil/testutil.go b/pgtype/testutil/testutil.go index 610f0710..d9aaa5c4 100644 --- a/pgtype/testutil/testutil.go +++ b/pgtype/testutil/testutil.go @@ -15,7 +15,7 @@ import ( _ "github.com/lib/pq" ) -func mustConnectDatabaseSQL(t testing.TB, driverName string) *sql.DB { +func MustConnectDatabaseSQL(t testing.TB, driverName string) *sql.DB { var sqlDriverName string switch driverName { case "github.com/lib/pq": @@ -34,7 +34,7 @@ func mustConnectDatabaseSQL(t testing.TB, driverName string) *sql.DB { return db } -func mustConnectPgx(t testing.TB) *pgx.Conn { +func MustConnectPgx(t testing.TB) *pgx.Conn { config, err := pgx.ParseURI(os.Getenv("DATABASE_URL")) if err != nil { t.Fatal(err) @@ -48,7 +48,7 @@ func mustConnectPgx(t testing.TB) *pgx.Conn { return conn } -func mustClose(t testing.TB, conn interface { +func MustClose(t testing.TB, conn interface { Close() error }) { err := conn.Close() @@ -73,7 +73,7 @@ func (f forceBinaryEncoder) EncodeBinary(ci *pgtype.ConnInfo, w io.Writer) (bool return f.e.EncodeBinary(ci, w) } -func forceEncoder(e interface{}, formatCode int16) interface{} { +func ForceEncoder(e interface{}, formatCode int16) interface{} { switch formatCode { case pgx.TextFormatCode: if e, ok := e.(pgtype.TextEncoder); ok { @@ -102,8 +102,8 @@ func TestSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []int } func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := MustConnectPgx(t) + defer MustClose(t, conn) ps, err := conn.Prepare("test", fmt.Sprintf("select $1::%s", pgTypeName)) if err != nil { @@ -121,7 +121,7 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values [] for i, v := range values { for _, fc := range formats { ps.FieldDescriptions[0].FormatCode = fc.formatCode - vEncoder := forceEncoder(v, fc.formatCode) + vEncoder := ForceEncoder(v, fc.formatCode) if vEncoder == nil { t.Logf("Skipping: %#v does not implement %v", v, fc.name) continue @@ -134,7 +134,7 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values [] } result := reflect.New(reflect.TypeOf(derefV)) - err := conn.QueryRow("test", forceEncoder(v, fc.formatCode)).Scan(result.Interface()) + err := conn.QueryRow("test", ForceEncoder(v, fc.formatCode)).Scan(result.Interface()) if err != nil { t.Errorf("%v %d: %v", fc.name, i, err) } @@ -147,8 +147,8 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values [] } func TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := MustConnectPgx(t) + defer MustClose(t, conn) for i, v := range values { // Derefence value if it is a pointer @@ -176,8 +176,8 @@ func TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName str } func TestDatabaseSQLSuccessfulTranscodeEqFunc(t testing.TB, driverName, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) { - conn := mustConnectDatabaseSQL(t, driverName) - defer mustClose(t, conn) + conn := MustConnectDatabaseSQL(t, driverName) + defer MustClose(t, conn) ps, err := conn.Prepare(fmt.Sprintf("select $1::%s", pgTypeName)) if err != nil { @@ -223,8 +223,8 @@ func TestSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFunc f } func TestPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFunc func(a, b interface{}) bool) { - conn := mustConnectPgx(t) - defer mustClose(t, conn) + conn := MustConnectPgx(t) + defer MustClose(t, conn) formats := []struct { name string @@ -243,7 +243,7 @@ func TestPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFun } ps.FieldDescriptions[0].FormatCode = fc.formatCode - if forceEncoder(tt.Value, fc.formatCode) == nil { + if ForceEncoder(tt.Value, fc.formatCode) == nil { t.Logf("Skipping: %#v does not implement %v", tt.Value, fc.name) continue } @@ -268,8 +268,8 @@ func TestPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFun } func TestDatabaseSQLSuccessfulNormalizeEqFunc(t testing.TB, driverName string, tests []NormalizeTest, eqFunc func(a, b interface{}) bool) { - conn := mustConnectDatabaseSQL(t, driverName) - defer mustClose(t, conn) + conn := MustConnectDatabaseSQL(t, driverName) + defer MustClose(t, conn) for i, tt := range tests { ps, err := conn.Prepare(tt.SQL) diff --git a/pgtype/text_array_test.go b/pgtype/text_array_test.go index 5a78d7bc..35ebef96 100644 --- a/pgtype/text_array_test.go +++ b/pgtype/text_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTextArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "text[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "text[]", []interface{}{ &pgtype.TextArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/text_test.go b/pgtype/text_test.go index 34b6a784..e4c1dbd8 100644 --- a/pgtype/text_test.go +++ b/pgtype/text_test.go @@ -6,11 +6,12 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTextTranscode(t *testing.T) { for _, pgTypeName := range []string{"text", "varchar"} { - testSuccessfulTranscode(t, pgTypeName, []interface{}{ + testutil.TestSuccessfulTranscode(t, pgTypeName, []interface{}{ pgtype.Text{String: "", Status: pgtype.Present}, pgtype.Text{String: "foo", Status: pgtype.Present}, pgtype.Text{Status: pgtype.Null}, diff --git a/pgtype/tid_test.go b/pgtype/tid_test.go index 56595ef4..7eb7773a 100644 --- a/pgtype/tid_test.go +++ b/pgtype/tid_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTidTranscode(t *testing.T) { - testSuccessfulTranscode(t, "tid", []interface{}{ + testutil.TestSuccessfulTranscode(t, "tid", []interface{}{ pgtype.Tid{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present}, pgtype.Tid{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present}, pgtype.Tid{Status: pgtype.Null}, diff --git a/pgtype/timestamp_array_test.go b/pgtype/timestamp_array_test.go index a15d3696..c75d101f 100644 --- a/pgtype/timestamp_array_test.go +++ b/pgtype/timestamp_array_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTimestampArrayTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "timestamp[]", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "timestamp[]", []interface{}{ &pgtype.TimestampArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/timestamp_test.go b/pgtype/timestamp_test.go index 58828806..c0427a5c 100644 --- a/pgtype/timestamp_test.go +++ b/pgtype/timestamp_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTimestampTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "timestamp", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "timestamp", []interface{}{ pgtype.Timestamp{Time: time.Date(1800, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, pgtype.Timestamp{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, pgtype.Timestamp{Time: time.Date(1905, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, diff --git a/pgtype/timestamptz_array_test.go b/pgtype/timestamptz_array_test.go index e0017828..50ee65d0 100644 --- a/pgtype/timestamptz_array_test.go +++ b/pgtype/timestamptz_array_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTimestamptzArrayTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "timestamptz[]", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "timestamptz[]", []interface{}{ &pgtype.TimestamptzArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/timestamptz_test.go b/pgtype/timestamptz_test.go index 6ddfc1bc..bbc001e5 100644 --- a/pgtype/timestamptz_test.go +++ b/pgtype/timestamptz_test.go @@ -6,10 +6,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTimestamptzTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "timestamptz", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "timestamptz", []interface{}{ pgtype.Timestamptz{Time: time.Date(1800, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}, pgtype.Timestamptz{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}, pgtype.Timestamptz{Time: time.Date(1905, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}, diff --git a/pgtype/tsrange_test.go b/pgtype/tsrange_test.go index 448cb92f..865233c2 100644 --- a/pgtype/tsrange_test.go +++ b/pgtype/tsrange_test.go @@ -5,10 +5,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTsrangeTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "tsrange", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "tsrange", []interface{}{ pgtype.Tsrange{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Status: pgtype.Present}, pgtype.Tsrange{ Lower: pgtype.Timestamp{Time: time.Date(1990, 12, 31, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, diff --git a/pgtype/tstzrange_test.go b/pgtype/tstzrange_test.go index 197aabbc..8eb00ab9 100644 --- a/pgtype/tstzrange_test.go +++ b/pgtype/tstzrange_test.go @@ -5,10 +5,11 @@ import ( "time" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestTstzrangeTranscode(t *testing.T) { - testSuccessfulTranscodeEqFunc(t, "tstzrange", []interface{}{ + testutil.TestSuccessfulTranscodeEqFunc(t, "tstzrange", []interface{}{ pgtype.Tstzrange{LowerType: pgtype.Empty, UpperType: pgtype.Empty, Status: pgtype.Present}, pgtype.Tstzrange{ Lower: pgtype.Timestamptz{Time: time.Date(1990, 12, 31, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, diff --git a/pgtype/uuid_test.go b/pgtype/uuid_test.go index 1eba7e90..b745d542 100644 --- a/pgtype/uuid_test.go +++ b/pgtype/uuid_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestUuidTranscode(t *testing.T) { - testSuccessfulTranscode(t, "uuid", []interface{}{ + testutil.TestSuccessfulTranscode(t, "uuid", []interface{}{ pgtype.Uuid{Bytes: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present}, pgtype.Uuid{Status: pgtype.Null}, }) diff --git a/pgtype/varbit_test.go b/pgtype/varbit_test.go index cd146d26..6c813aae 100644 --- a/pgtype/varbit_test.go +++ b/pgtype/varbit_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestVarbitTranscode(t *testing.T) { - testSuccessfulTranscode(t, "varbit", []interface{}{ + testutil.TestSuccessfulTranscode(t, "varbit", []interface{}{ &pgtype.Varbit{Bytes: []byte{}, Len: 0, Status: pgtype.Present}, &pgtype.Varbit{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Status: pgtype.Present}, &pgtype.Varbit{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Status: pgtype.Present}, @@ -16,10 +17,10 @@ func TestVarbitTranscode(t *testing.T) { } func TestVarbitNormalize(t *testing.T) { - testSuccessfulNormalize(t, []normalizeTest{ + testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{ { - sql: "select B'111111111'", - value: &pgtype.Varbit{Bytes: []byte{255, 128}, Len: 9, Status: pgtype.Present}, + SQL: "select B'111111111'", + Value: &pgtype.Varbit{Bytes: []byte{255, 128}, Len: 9, Status: pgtype.Present}, }, }) } diff --git a/pgtype/varchar_array_test.go b/pgtype/varchar_array_test.go index 4a8b09b8..7d6fb39b 100644 --- a/pgtype/varchar_array_test.go +++ b/pgtype/varchar_array_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestVarcharArrayTranscode(t *testing.T) { - testSuccessfulTranscode(t, "varchar[]", []interface{}{ + testutil.TestSuccessfulTranscode(t, "varchar[]", []interface{}{ &pgtype.VarcharArray{ Elements: nil, Dimensions: nil, diff --git a/pgtype/xid_test.go b/pgtype/xid_test.go index 11dd0615..868c101e 100644 --- a/pgtype/xid_test.go +++ b/pgtype/xid_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/jackc/pgx/pgtype" + "github.com/jackc/pgx/pgtype/testutil" ) func TestXidTranscode(t *testing.T) { @@ -17,13 +18,13 @@ func TestXidTranscode(t *testing.T) { return reflect.DeepEqual(a, b) } - testPgxSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) + testutil.TestPgxSuccessfulTranscodeEqFunc(t, pgTypeName, values, eqFunc) // No direct conversion from int to xid, convert through text - testPgxSimpleProtocolSuccessfulTranscodeEqFunc(t, "text::"+pgTypeName, values, eqFunc) + testutil.TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t, "text::"+pgTypeName, values, eqFunc) for _, driverName := range []string{"github.com/lib/pq", "github.com/jackc/pgx/stdlib"} { - testDatabaseSQLSuccessfulTranscodeEqFunc(t, driverName, pgTypeName, values, eqFunc) + testutil.TestDatabaseSQLSuccessfulTranscodeEqFunc(t, driverName, pgTypeName, values, eqFunc) } }