forked from jackc/pgtype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacaddr_test.go
78 lines (66 loc) · 1.81 KB
/
macaddr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pgtype_test
import (
"bytes"
"net"
"reflect"
"testing"
"github.com/jackc/pgx/v4/pgtype"
"github.com/jackc/pgx/v4/pgtype/testutil"
)
func TestMacaddrTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "macaddr", []interface{}{
&pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
&pgtype.Macaddr{Status: pgtype.Null},
})
}
func TestMacaddrSet(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.Macaddr
}{
{
source: mustParseMacaddr(t, "01:23:45:67:89:ab"),
result: pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
},
{
source: "01:23:45:67:89:ab",
result: pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
},
}
for i, tt := range successfulTests {
var r pgtype.Macaddr
err := r.Set(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
}
if !reflect.DeepEqual(r, tt.result) {
t.Errorf("%d: expected %v to convert to %v, but it was %v", i, tt.source, tt.result, r)
}
}
}
func TestMacaddrAssignTo(t *testing.T) {
{
src := pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present}
var dst net.HardwareAddr
expected := mustParseMacaddr(t, "01:23:45:67:89:ab")
err := src.AssignTo(&dst)
if err != nil {
t.Error(err)
}
if bytes.Compare([]byte(dst), []byte(expected)) != 0 {
t.Errorf("expected %v to assign %v, but result was %v", src, expected, dst)
}
}
{
src := pgtype.Macaddr{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present}
var dst string
expected := "01:23:45:67:89:ab"
err := src.AssignTo(&dst)
if err != nil {
t.Error(err)
}
if dst != expected {
t.Errorf("expected %v to assign %v, but result was %v", src, expected, dst)
}
}
}