Skip to content

Commit

Permalink
test: add UUID encoding/decoding as a struct field
Browse files Browse the repository at this point in the history
The test fails with msgpack.v2 [1].

1. #211
  • Loading branch information
oleg-jukovec committed Sep 5, 2022
1 parent 5801dc6 commit a1dc209
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions uuid/msgpack_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ import (
)

type decoder = msgpack.Decoder

func marshal(v interface{}) ([]byte, error) {
return msgpack.Marshal(v)
}

func unmarshal(data []byte, v interface{}) error {
return msgpack.Unmarshal(data, v)
}
8 changes: 8 additions & 0 deletions uuid/msgpack_v5_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ import (
)

type decoder = msgpack.Decoder

func marshal(v interface{}) ([]byte, error) {
return msgpack.Marshal(v)
}

func unmarshal(data []byte, v interface{}) error {
return msgpack.Unmarshal(data, v)
}
24 changes: 24 additions & 0 deletions uuid/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ func TestReplace(t *testing.T) {
tupleValueIsId(t, respSel.Data, id)
}

type marshalComplexTuple struct {
UUID uuid.UUID
Name string
}

func TestMarshalComplex(t *testing.T) {
space := marshalComplexTuple{UUID: uuid.New(), Name: "foo bar"}

b, err := marshal(&space)
if err != nil {
t.Fatalf("Unable to marshal: %s", err)
}

var item marshalComplexTuple
err = unmarshal(b, &item)
if err != nil {
t.Fatalf("Unable to unmarshal: %s", err)
}

if item.Name != space.Name {
t.Fatalf("names is not equal: %s != %s", space.Name, item.Name)
}
}

// runTestMain is a body of TestMain function
// (see https://pkg.go.dev/testing#hdr-Main).
// Using defer + os.Exit is not works so TestMain body
Expand Down

0 comments on commit a1dc209

Please sign in to comment.