mirror of
https://github.com/jackc/pgx.git
synced 2025-05-17 13:01:05 +00:00
Added ValueRoundTripTest to pgxtest Removed pgtype/testutil pgtype tests now run with all (applicable) query modes. This gives better coverage than before and revealed several bugs which are also fixed in this commit.
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package pgtype_test
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgxtest"
|
|
)
|
|
|
|
func isExpectedEqHardwareAddr(a interface{}) func(interface{}) bool {
|
|
return func(v interface{}) bool {
|
|
aa := a.(net.HardwareAddr)
|
|
vv := v.(net.HardwareAddr)
|
|
|
|
if (aa == nil) != (vv == nil) {
|
|
return false
|
|
}
|
|
|
|
if aa == nil {
|
|
return true
|
|
}
|
|
|
|
return bytes.Compare(aa, vv) == 0
|
|
}
|
|
}
|
|
|
|
func TestMacaddrCodec(t *testing.T) {
|
|
skipCockroachDB(t, "Server does not support type macaddr")
|
|
|
|
// Only testing known OID query exec modes as net.HardwareAddr could map to macaddr or macaddr8.
|
|
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, pgxtest.KnownOIDQueryExecModes, "macaddr", []pgxtest.ValueRoundTripTest{
|
|
{
|
|
mustParseMacaddr(t, "01:23:45:67:89:ab"),
|
|
new(net.HardwareAddr),
|
|
isExpectedEqHardwareAddr(mustParseMacaddr(t, "01:23:45:67:89:ab")),
|
|
},
|
|
{
|
|
"01:23:45:67:89:ab",
|
|
new(net.HardwareAddr),
|
|
isExpectedEqHardwareAddr(mustParseMacaddr(t, "01:23:45:67:89:ab")),
|
|
},
|
|
{
|
|
mustParseMacaddr(t, "01:23:45:67:89:ab"),
|
|
new(string),
|
|
isExpectedEq("01:23:45:67:89:ab"),
|
|
},
|
|
{nil, new(*net.HardwareAddr), isExpectedEq((*net.HardwareAddr)(nil))},
|
|
})
|
|
}
|