mirror of https://github.com/jackc/pgx.git
Restore test from v4
parent
93c79d7d41
commit
d5807f01ed
|
@ -203,6 +203,57 @@ func TestTypeMapScanUnknownOIDIntoSQLScanner(t *testing.T) {
|
||||||
assert.False(t, s.Valid)
|
assert.False(t, s.Valid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pgCustomInt int64
|
||||||
|
|
||||||
|
func (ci *pgCustomInt) Scan(src interface{}) error {
|
||||||
|
*ci = pgCustomInt(src.(int64))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestScanPlanBinaryInt32ScanScanner(t *testing.T) {
|
||||||
|
ci := pgtype.NewMap()
|
||||||
|
src := []byte{0, 42}
|
||||||
|
var v pgCustomInt
|
||||||
|
|
||||||
|
plan := ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, &v)
|
||||||
|
err := plan.Scan(src, &v)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, 42, v)
|
||||||
|
|
||||||
|
ptr := new(pgCustomInt)
|
||||||
|
plan = ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, &ptr)
|
||||||
|
err = plan.Scan(src, &ptr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, 42, *ptr)
|
||||||
|
|
||||||
|
ptr = new(pgCustomInt)
|
||||||
|
err = plan.Scan(nil, &ptr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Nil(t, ptr)
|
||||||
|
|
||||||
|
ptr = nil
|
||||||
|
plan = ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, &ptr)
|
||||||
|
err = plan.Scan(src, &ptr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, 42, *ptr)
|
||||||
|
|
||||||
|
ptr = nil
|
||||||
|
plan = ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, &ptr)
|
||||||
|
err = plan.Scan(nil, &ptr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Nil(t, ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test for https://github.com/jackc/pgtype/issues/164
|
||||||
|
func TestScanPlanInterface(t *testing.T) {
|
||||||
|
ci := pgtype.NewMap()
|
||||||
|
src := []byte{0, 42}
|
||||||
|
var v interface{}
|
||||||
|
plan := ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, v)
|
||||||
|
err := plan.Scan(src, v)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
||||||
m := pgtype.NewMap()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
|
|
Loading…
Reference in New Issue