Skip to content

Commit a1dc209

Browse files
committed
test: add UUID encoding/decoding as a struct field
The test fails with msgpack.v2 [1]. 1. #211
1 parent 5801dc6 commit a1dc209

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

uuid/msgpack_helper_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ import (
88
)
99

1010
type decoder = msgpack.Decoder
11+
12+
func marshal(v interface{}) ([]byte, error) {
13+
return msgpack.Marshal(v)
14+
}
15+
16+
func unmarshal(data []byte, v interface{}) error {
17+
return msgpack.Unmarshal(data, v)
18+
}

uuid/msgpack_v5_helper_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ import (
88
)
99

1010
type decoder = msgpack.Decoder
11+
12+
func marshal(v interface{}) ([]byte, error) {
13+
return msgpack.Marshal(v)
14+
}
15+
16+
func unmarshal(data []byte, v interface{}) error {
17+
return msgpack.Unmarshal(data, v)
18+
}

uuid/uuid_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ func TestReplace(t *testing.T) {
133133
tupleValueIsId(t, respSel.Data, id)
134134
}
135135

136+
type marshalComplexTuple struct {
137+
UUID uuid.UUID
138+
Name string
139+
}
140+
141+
func TestMarshalComplex(t *testing.T) {
142+
space := marshalComplexTuple{UUID: uuid.New(), Name: "foo bar"}
143+
144+
b, err := marshal(&space)
145+
if err != nil {
146+
t.Fatalf("Unable to marshal: %s", err)
147+
}
148+
149+
var item marshalComplexTuple
150+
err = unmarshal(b, &item)
151+
if err != nil {
152+
t.Fatalf("Unable to unmarshal: %s", err)
153+
}
154+
155+
if item.Name != space.Name {
156+
t.Fatalf("names is not equal: %s != %s", space.Name, item.Name)
157+
}
158+
}
159+
136160
// runTestMain is a body of TestMain function
137161
// (see https://pkg.go.dev/testing#hdr-Main).
138162
// Using defer + os.Exit is not works so TestMain body

0 commit comments

Comments
 (0)