...
1 package pgtype_test
2
3 import (
4 "bytes"
5 "context"
6 "net"
7 "testing"
8
9 "github.com/jackc/pgx/v5/pgxtest"
10 )
11
12 func isExpectedEqHardwareAddr(a any) func(any) bool {
13 return func(v any) bool {
14 aa := a.(net.HardwareAddr)
15 vv := v.(net.HardwareAddr)
16
17 if (aa == nil) != (vv == nil) {
18 return false
19 }
20
21 if aa == nil {
22 return true
23 }
24
25 return bytes.Equal(aa, vv)
26 }
27 }
28
29 func TestMacaddrCodec(t *testing.T) {
30 skipCockroachDB(t, "Server does not support type macaddr")
31
32
33 pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, pgxtest.KnownOIDQueryExecModes, "macaddr", []pgxtest.ValueRoundTripTest{
34 {
35 mustParseMacaddr(t, "01:23:45:67:89:ab"),
36 new(net.HardwareAddr),
37 isExpectedEqHardwareAddr(mustParseMacaddr(t, "01:23:45:67:89:ab")),
38 },
39 {
40 "01:23:45:67:89:ab",
41 new(net.HardwareAddr),
42 isExpectedEqHardwareAddr(mustParseMacaddr(t, "01:23:45:67:89:ab")),
43 },
44 {
45 mustParseMacaddr(t, "01:23:45:67:89:ab"),
46 new(string),
47 isExpectedEq("01:23:45:67:89:ab"),
48 },
49 {nil, new(*net.HardwareAddr), isExpectedEq((*net.HardwareAddr)(nil))},
50 })
51 }
52
View as plain text