From 08e0e48b47628c2420dbe4de44a24eb9df337f7e Mon Sep 17 00:00:00 2001 From: Brian McQueen Date: Sat, 25 Jun 2022 18:48:25 -0700 Subject: [PATCH] added some testing tools and fixed an intermittent failure in the two way json test cases --- go.mod | 5 ++++- go.sum | 14 ++++++++++++++ text_test.go | 24 +++++++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7573301..f282a30 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/linkedin/goavro/v2 go 1.12 -require github.com/golang/snappy v0.0.1 +require ( + github.com/golang/snappy v0.0.1 + github.com/stretchr/testify v1.7.5 +) diff --git a/go.sum b/go.sum index 331e6a1..9532d30 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,16 @@ +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/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +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= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= +github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/text_test.go b/text_test.go index 596d302..553751a 100644 --- a/text_test.go +++ b/text_test.go @@ -11,9 +11,12 @@ package goavro import ( "bytes" + "encoding/json" "fmt" "math" "testing" + + "github.com/stretchr/testify/assert" ) func testTextDecodeFail(t *testing.T, schema string, buf []byte, errorMessage string) { @@ -87,14 +90,29 @@ func testNativeToTextualJsonPass(t *testing.T, schema string, datum interface{}, } toTextualAndCompare(t, schema, datum, encoded, codec) } -func toTextualAndCompare(t *testing.T, schema string, datum interface{}, encoded []byte, codec *Codec) { + +func toTextualAndCompare(t *testing.T, schema string, datum interface{}, expected []byte, codec *Codec) { t.Helper() decoded, err := codec.TextualFromNative(nil, datum) if err != nil { t.Fatalf("schema: %s; %s", schema, err) } - if !bytes.Equal(decoded, encoded) { - t.Errorf("GOT: %v; WANT: %v", string(decoded), string(encoded)) + + // do extra stuff to to the challenge equality of maps + var want interface{} + + if err := json.Unmarshal(expected, &want); err != nil { + t.Errorf("Could not unmarshal the expected data into a go struct:%#v:", string(expected)) + } + + var got interface{} + + if err := json.Unmarshal(decoded, &got); err != nil { + t.Errorf("Could not unmarshal the received data into a go struct:%#v:", string(decoded)) + } + + if !assert.Equal(t, want, got) { + t.Errorf("GOT: %v; WANT: %v", string(decoded), string(expected)) } }