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
This commit is contained in:
Pavan BG 2021-05-20 21:33:07 +05:30
parent d9c5e1f0a2
commit 319ef4aa42

View File

@ -15,31 +15,23 @@
package testutil package testutil
import ( import (
"fmt"
"reflect" "reflect"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func AssertEqual(t *testing.T, e, a interface{}, msg ...string) { func copyToInterface(msg ...string) []interface{} {
t.Helper() newMsg := make([]interface{}, len(msg))
if (e == nil || a == nil) && (isNil(e) && isNil(a)) { for i, v := range msg {
return newMsg[i] = v
} }
if reflect.DeepEqual(e, a) { return newMsg
return
}
s := ""
if len(msg) > 0 {
s = msg[0] + ": "
}
s = fmt.Sprintf("%s:expected %+v, got %+v", s, e, a)
FatalStack(t, s)
} }
func AssertNil(t *testing.T, v interface{}) { func AssertNil(t *testing.T, v interface{}) {
t.Helper() t.Helper()
AssertEqual(t, nil, v) assert.Equal(t, nil, v)
} }
func AssertNotNil(t *testing.T, v interface{}) { 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) { func AssertTrue(t *testing.T, v bool, msg ...string) {
t.Helper() 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) { func AssertFalse(t *testing.T, v bool, msg ...string) {
t.Helper() t.Helper()
AssertEqual(t, false, v, msg...) newMsg := copyToInterface(msg...)
assert.Equal(t, false, v, newMsg)
} }
func isNil(v interface{}) bool { func isNil(v interface{}) bool {