-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.go
37 lines (32 loc) · 939 Bytes
/
check.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
package testing
import (
"errors"
"reflect"
"strings"
)
// Comparator returns true if x and y are equal (as determined by the Comparator function).
// x and y are the returned and expected value respectively from a function being tested.
// The default Comparator uses reflect.DeepEqual. However, the github.com/google/go-cmp package
// may also be used. See: https://github.com/google/go-cmp.
type Comparator func(x, y interface{}) bool
type errComparator func(err, target error) bool
func deepEqual(err, target error) bool {
switch target := target.(type) {
case ErrContains:
if err == nil {
return false
}
return strings.Contains(err.Error(), target.Substr)
}
return reflect.DeepEqual(err, target)
}
func is(err, target error) bool {
switch target := target.(type) {
case ErrContains:
if err == nil {
return false
}
return strings.Contains(err.Error(), target.Substr)
}
return errors.Is(err, target)
}