Skip to content

Commit f9d96bf

Browse files
author
Alexander Zielenski
committed
use reflect.DeepEqual for gnostic test comparisons
1 parent 1aeb6d8 commit f9d96bf

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/validation/spec/gnostic_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1827
func 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

337350
func TestGnosticConversionSmallDeterministic(t *testing.T) {

0 commit comments

Comments
 (0)