-
Notifications
You must be signed in to change notification settings - Fork 598
/
assert_test.go
50 lines (44 loc) · 1.03 KB
/
assert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package bigcache
import (
"bytes"
"fmt"
"path"
"reflect"
"runtime"
"testing"
)
func assertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
if !objectsAreEqual(expected, actual) {
_, file, line, _ := runtime.Caller(1)
file = path.Base(file)
t.Errorf(fmt.Sprintf("\n%s:%d: Not equal: \n"+
"expected: %T(%#v)\n"+
"actual : %T(%#v)\n",
file, line, expected, expected, actual, actual), msgAndArgs...)
}
}
func noError(t *testing.T, e error) {
if e != nil {
_, file, line, _ := runtime.Caller(1)
file = path.Base(file)
t.Errorf(fmt.Sprintf("\n%s:%d: Error is not nil: \n"+
"actual : %T(%#v)\n", file, line, e, e))
}
}
func objectsAreEqual(expected, actual interface{}) bool {
if expected == nil || actual == nil {
return expected == actual
}
exp, ok := expected.([]byte)
if !ok {
return reflect.DeepEqual(expected, actual)
}
act, ok := actual.([]byte)
if !ok {
return false
}
if exp == nil || act == nil {
return exp == nil && act == nil
}
return bytes.Equal(exp, act)
}