-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
56 lines (47 loc) · 1.33 KB
/
error_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
54
55
56
package errors
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
)
func TestErrors(t *testing.T) {
errorFuncs := map[string]func() error{
"plain": func() error { return New("error") },
"errorf": func() error {
return Errorf("error: %v", true)
},
"witherror": func() error {
return WithError(errors.New("some error"), "error: %v", true)
},
"grpc": func() error {
return GRPC(codes.Aborted, "whoops: %v", 420)
},
}
for name, fun := range errorFuncs {
WithCaller = false
WithCallerVerbose = false
WithStack = false
err := fun()
assert.Error(t, err, name)
assert.Contains(t, err.Error(), "error", name)
assert.IsType(t, err, WithLocation{}, name)
assert.Error(t, err.(WithLocation).Err)
WithCaller = true
err = fun()
assert.Error(t, err, name)
assert.Contains(t, err.Error(), "tinyci/errors.TestErrors", name)
assert.IsType(t, err, WithLocation{}, name)
WithCallerVerbose = true
err = fun()
assert.Error(t, err, name)
assert.Contains(t, err.Error(), "error_test.go", name)
assert.IsType(t, err, WithLocation{}, name)
WithStack = true
err = fun()
assert.Error(t, err, name)
assert.Contains(t, err.Error(), "STACK TRACE", name)
assert.Contains(t, err.Error(), "WithLocation.Error", name)
assert.IsType(t, err, WithLocation{}, name)
}
}