-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy patherrors_test.go
53 lines (41 loc) · 1.29 KB
/
errors_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
51
52
53
package errors
import (
"testing"
)
func checkErrorMessage(t *testing.T, err error, message string) {
t.Helper()
if got, want := err.Error(), message; got != want {
t.Errorf("error message does not match the expectd\nactual: %s\nexpected: %s", got, want)
}
}
func checkFormat(t *testing.T, err error, formats map[string][]string) {
t.Helper()
i := 1
for format, want := range formats {
testFormatCompleteCompare(t, i, err, format, want, true)
i++
}
}
func checkErrorNil(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Errorf("nil error is expected to result in nil\nactual: %#v", err)
}
}
func checkUnwrap(t *testing.T, err error, origErr error) {
t.Helper()
if err, ok := err.(interface{ Unwrap() error }); ok {
if got, want := err.Unwrap(), origErr; got != want {
t.Errorf("error does not match the expected one\nactual: %#v\nexpected: %#v", got, want)
}
} else {
t.Fatal("error does not implement the wrapper (interface{ Unwrap() error}) interface")
}
if err, ok := err.(interface{ Cause() error }); ok {
if got, want := err.Cause(), origErr; got != want {
t.Errorf("error does not match the expected one\nactual: %#v\nexpected: %#v", got, want)
}
} else {
t.Fatal("error does not implement the causer (interface{ Cause() error}) interface")
}
}