Skip to content

Commit

Permalink
added some testing tools and fixed an intermittent failure in the two…
Browse files Browse the repository at this point in the history
… way json test cases
  • Loading branch information
xmcqueen committed Jun 26, 2022
1 parent 441afb4 commit 08e0e48
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
24 changes: 21 additions & 3 deletions text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 08e0e48

Please sign in to comment.