@@ -4,17 +4,26 @@ import (
44 "encoding/json"
55 "io"
66 "os"
7+ "reflect"
78 "testing"
89 "time"
910
1011 "github.com/go-openapi/jsonreference"
12+ "github.com/google/go-cmp/cmp"
1113 fuzz "github.com/google/gofuzz"
1214 openapi_v2 "github.com/googleapis/gnostic/openapiv2"
1315 "github.com/stretchr/testify/assert"
1416 "github.com/stretchr/testify/require"
1517 "google.golang.org/protobuf/proto"
1618)
1719
20+ var SpecV2DiffOptions = []cmp.Option {
21+ // cmp.Diff panics on Ref since jsonreference.Ref uses unexported fields
22+ cmp .Comparer (func (a Ref , b Ref ) bool {
23+ return a .String () == b .String ()
24+ }),
25+ }
26+
1827func gnosticCommonTest (t testing.TB , fuzzer * fuzz.Fuzzer ) {
1928 fuzzer .Funcs (
2029 func (v * * Paths , c fuzz.Continue ) {
@@ -327,11 +336,15 @@ func gnosticCommonTest(t testing.TB, fuzzer *fuzz.Fuzzer) {
327336
328337 actual := Swagger {}
329338 require .NoError (t , actual .FromGnostic (gnosticSpec ))
330- require .EqualValues (t , expected , actual )
339+ if ! reflect .DeepEqual (expected , actual ) {
340+ t .Fatal (cmp .Diff (expected , actual , SpecV2DiffOptions ... ))
341+ }
331342
332343 newJsonBytes , err := json .Marshal (actual )
333344 require .NoError (t , err )
334- require .Equal (t , string (jsonBytes ), string (newJsonBytes ))
345+ if ! reflect .DeepEqual (jsonBytes , newJsonBytes ) {
346+ t .Fatal (cmp .Diff (string (jsonBytes ), string (newJsonBytes ), SpecV2DiffOptions ... ))
347+ }
335348}
336349
337350func TestGnosticConversionSmallDeterministic (t * testing.T ) {
0 commit comments