From 319ef4aa42c64481ea337f34b2561429ea49ff4d Mon Sep 17 00:00:00 2001 From: Pavan BG Date: Thu, 20 May 2021 21:33:07 +0530 Subject: [PATCH] client: Removed AssertEqual function Used github.com/stretchr/testify/assert to replace the AssertEqual function definition. Required the use of copyToInterface to copy a string slice to the empty interface slice --- client/pkg/testutil/assert.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/client/pkg/testutil/assert.go b/client/pkg/testutil/assert.go index 7222a1700..0d241e3e0 100644 --- a/client/pkg/testutil/assert.go +++ b/client/pkg/testutil/assert.go @@ -15,31 +15,23 @@ package testutil import ( - "fmt" "reflect" "testing" + + "github.com/stretchr/testify/assert" ) -func AssertEqual(t *testing.T, e, a interface{}, msg ...string) { - t.Helper() - if (e == nil || a == nil) && (isNil(e) && isNil(a)) { - return +func copyToInterface(msg ...string) []interface{} { + newMsg := make([]interface{}, len(msg)) + for i, v := range msg { + newMsg[i] = v } - if reflect.DeepEqual(e, a) { - return - } - s := "" - if len(msg) > 0 { - s = msg[0] + ": " - } - - s = fmt.Sprintf("%s:expected %+v, got %+v", s, e, a) - FatalStack(t, s) + return newMsg } func AssertNil(t *testing.T, v interface{}) { t.Helper() - AssertEqual(t, nil, v) + assert.Equal(t, nil, v) } func AssertNotNil(t *testing.T, v interface{}) { @@ -51,12 +43,14 @@ func AssertNotNil(t *testing.T, v interface{}) { func AssertTrue(t *testing.T, v bool, msg ...string) { t.Helper() - AssertEqual(t, true, v, msg...) + newMsg := copyToInterface(msg...) + assert.Equal(t, true, v, newMsg) } func AssertFalse(t *testing.T, v bool, msg ...string) { t.Helper() - AssertEqual(t, false, v, msg...) + newMsg := copyToInterface(msg...) + assert.Equal(t, false, v, newMsg) } func isNil(v interface{}) bool {