From aeecf3320b130bb520dcf8c2a3418ea10d4210d5 Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Fri, 5 Apr 2019 21:57:31 +0900 Subject: [PATCH] Use pretty for deep equal --- validate.go | 6 +++--- validate_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/validate.go b/validate.go index 33d79e3..35e819f 100644 --- a/validate.go +++ b/validate.go @@ -5,10 +5,10 @@ import ( "fmt" "net/http" "net/url" - "reflect" "testing" "github.com/golang/protobuf/proto" + "github.com/kylelemons/godebug/pretty" "github.com/tenntenn/gpath" ) @@ -16,8 +16,8 @@ var ( defaultUnmarshalFunc = json.Unmarshal defaultAssertFunc = func(t *testing.T, expected, actual interface{}, desc string) { - if !reflect.DeepEqual(expected, actual) { - tFatalf(t, "%s: got %#v(%T), want %#v(%T)", desc, actual, actual, expected, expected) + if diff := pretty.Compare(actual, expected); diff != "" { + tFatalf(t, "%s: (-got +want): \n%s", desc, diff) } } diff --git a/validate_test.go b/validate_test.go index 7f318b3..964aba8 100644 --- a/validate_test.go +++ b/validate_test.go @@ -403,7 +403,7 @@ func TestAssertFunc(t *testing.T) { var buf bytes.Buffer tFatalf = fprintFatalFunc(&buf) defaultAssertFunc(t, 1, 2, "test-assert") - if got, want := buf.String(), "test-assert: got 2(int), want 1(int)"; !strings.Contains(got, want) { + if got, want := buf.String(), "test-assert: (-got +want): \n-2\n+1"; !strings.Contains(got, want) { t.Fatalf("expect %q to contain %q", got, want) }