diff --git a/go.mod b/go.mod index 94363fc..1779cfb 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,8 @@ module github.com/vmihailenco/msgpack/v5 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kr/pretty v0.1.0 // indirect github.com/stretchr/testify v1.6.1 github.com/vmihailenco/tagparser v0.1.2 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 ) go 1.11 diff --git a/go.sum b/go.sum index a21ed8d..309f684 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,5 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -13,8 +7,7 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/msgpack_test.go b/msgpack_test.go index b9442a0..66ce312 100644 --- a/msgpack_test.go +++ b/msgpack_test.go @@ -3,14 +3,14 @@ package msgpack_test import ( "bufio" "bytes" + "fmt" "math" "reflect" "testing" "time" "github.com/stretchr/testify/require" - . "gopkg.in/check.v1" - + "github.com/stretchr/testify/suite" "github.com/vmihailenco/msgpack/v5" ) @@ -18,69 +18,69 @@ type nameStruct struct { Name string } -func TestGocheck(t *testing.T) { TestingT(t) } - type MsgpackTest struct { + suite.Suite + buf *bytes.Buffer enc *msgpack.Encoder dec *msgpack.Decoder } -var _ = Suite(&MsgpackTest{}) - -func (t *MsgpackTest) SetUpTest(c *C) { +func (t *MsgpackTest) SetUpTest() { t.buf = &bytes.Buffer{} t.enc = msgpack.NewEncoder(t.buf) t.dec = msgpack.NewDecoder(bufio.NewReader(t.buf)) } -func (t *MsgpackTest) TestDecodeNil(c *C) { - c.Assert(t.dec.Decode(nil), NotNil) +func (t *MsgpackTest) TestDecodeNil() { + t.NotNil(t.dec.Decode(nil)) } -func (t *MsgpackTest) TestTime(c *C) { +func (t *MsgpackTest) TestTime() { in := time.Now() var out time.Time - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Equal(in), Equals, true) + + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.True(out.Equal(in)) var zero time.Time - c.Assert(t.enc.Encode(zero), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Equal(zero), Equals, true) - c.Assert(out.IsZero(), Equals, true) + t.Nil(t.enc.Encode(zero)) + t.Nil(t.dec.Decode(&out)) + t.True(out.Equal(zero)) + t.True(out.IsZero()) + } -func (t *MsgpackTest) TestLargeBytes(c *C) { +func (t *MsgpackTest) TestLargeBytes() { N := int(1e6) src := bytes.Repeat([]byte{'1'}, N) - c.Assert(t.enc.Encode(src), IsNil) + t.Nil(t.enc.Encode(src)) var dst []byte - c.Assert(t.dec.Decode(&dst), IsNil) - c.Assert(dst, DeepEquals, src) + t.Nil(t.dec.Decode(&dst)) + t.Equal(dst, src) } -func (t *MsgpackTest) TestLargeString(c *C) { +func (t *MsgpackTest) TestLargeString() { N := int(1e6) src := string(bytes.Repeat([]byte{'1'}, N)) - c.Assert(t.enc.Encode(src), IsNil) + t.Nil(t.enc.Encode(src)) var dst string - c.Assert(t.dec.Decode(&dst), IsNil) - c.Assert(dst, Equals, src) + t.Nil(t.dec.Decode(&dst)) + t.Equal(dst, src) } -func (t *MsgpackTest) TestSliceOfStructs(c *C) { - in := []*nameStruct{&nameStruct{"hello"}} +func (t *MsgpackTest) TestSliceOfStructs() { + in := []*nameStruct{{"hello"}} var out []*nameStruct - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out, DeepEquals, in) + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out, in) } -func (t *MsgpackTest) TestMap(c *C) { +func (t *MsgpackTest) TestMap() { for _, i := range []struct { m map[string]string b []byte @@ -88,24 +88,24 @@ func (t *MsgpackTest) TestMap(c *C) { {map[string]string{}, []byte{0x80}}, {map[string]string{"hello": "world"}, []byte{0x81, 0xa5, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xa5, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, } { - c.Assert(t.enc.Encode(i.m), IsNil) - c.Assert(t.buf.Bytes(), DeepEquals, i.b, Commentf("err encoding %v", i.m)) + t.Nil(t.enc.Encode(i.m)) + t.Equal(t.buf.Bytes(), i.b, fmt.Errorf("err encoding %v", i.m)) var m map[string]string - c.Assert(t.dec.Decode(&m), IsNil) - c.Assert(m, DeepEquals, i.m) + t.Nil(t.dec.Decode(&m)) + t.Equal(m, i.m) } } -func (t *MsgpackTest) TestStructNil(c *C) { +func (t *MsgpackTest) TestStructNil() { var dst *nameStruct - c.Assert(t.enc.Encode(nameStruct{Name: "foo"}), IsNil) - c.Assert(t.dec.Decode(&dst), IsNil) - c.Assert(dst, Not(IsNil)) - c.Assert(dst.Name, Equals, "foo") + t.Nil(t.enc.Encode(nameStruct{Name: "foo"})) + t.Nil(t.dec.Decode(&dst)) + t.NotNil(dst) + t.Equal(dst.Name, "foo") } -func (t *MsgpackTest) TestStructUnknownField(c *C) { +func (t *MsgpackTest) TestStructUnknownField() { in := struct { Field1 string Field2 string @@ -115,13 +115,13 @@ func (t *MsgpackTest) TestStructUnknownField(c *C) { Field2: "value2", Field3: "value3", } - c.Assert(t.enc.Encode(in), IsNil) + t.Nil(t.enc.Encode(in)) out := struct { Field2 string }{} - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Field2, Equals, "value2") + t.Nil(t.dec.Decode(&out)) + t.Equal(out.Field2, "value2") } //------------------------------------------------------------------------------ @@ -151,45 +151,45 @@ func (s *coderStruct) DecodeMsgpack(dec *msgpack.Decoder) error { return dec.Decode(&s.name) } -func (t *MsgpackTest) TestCoder(c *C) { +func (t *MsgpackTest) TestCoder() { in := &coderStruct{name: "hello"} var out coderStruct - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Name(), Equals, "hello") + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out.Name(), "hello") } -func (t *MsgpackTest) TestNilCoder(c *C) { +func (t *MsgpackTest) TestNilCoder() { in := &coderStruct{name: "hello"} var out *coderStruct - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Name(), Equals, "hello") + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out.Name(), "hello") } -func (t *MsgpackTest) TestNilCoderValue(c *C) { +func (t *MsgpackTest) TestNilCoderValue() { in := &coderStruct{name: "hello"} var out *coderStruct - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.DecodeValue(reflect.ValueOf(&out)), IsNil) - c.Assert(out.Name(), Equals, "hello") + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.DecodeValue(reflect.ValueOf(&out))) + t.Equal(out.Name(), "hello") } -func (t *MsgpackTest) TestPtrToCoder(c *C) { +func (t *MsgpackTest) TestPtrToCoder() { in := &coderStruct{name: "hello"} var out coderStruct out2 := &out - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out2), IsNil) - c.Assert(out.Name(), Equals, "hello") + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out2)) + t.Equal(out.Name(), "hello") } -func (t *MsgpackTest) TestWrappedCoder(c *C) { +func (t *MsgpackTest) TestWrappedCoder() { in := &wrapperStruct{coderStruct: coderStruct{name: "hello"}} var out wrapperStruct - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Name(), Equals, "hello") + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out.Name(), "hello") } //------------------------------------------------------------------------------ @@ -203,13 +203,13 @@ type struct1 struct { Struct2 struct2 } -func (t *MsgpackTest) TestNestedStructs(c *C) { +func (t *MsgpackTest) TestNestedStructs() { in := &struct1{Name: "hello", Struct2: struct2{Name: "world"}} var out struct1 - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out.Name, Equals, in.Name) - c.Assert(out.Struct2.Name, Equals, in.Struct2.Name) + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out.Name, in.Name) + t.Equal(out.Struct2.Name, in.Struct2.Name) } type Struct4 struct { @@ -247,13 +247,13 @@ func TestEmbedding(t *testing.T) { } } -func (t *MsgpackTest) TestSliceNil(c *C) { +func (t *MsgpackTest) TestSliceNil() { in := [][]*int{nil} var out [][]*int - c.Assert(t.enc.Encode(in), IsNil) - c.Assert(t.dec.Decode(&out), IsNil) - c.Assert(out, DeepEquals, in) + t.Nil(t.enc.Encode(in)) + t.Nil(t.dec.Decode(&out)) + t.Equal(out, in) } //------------------------------------------------------------------------------