-
Notifications
You must be signed in to change notification settings - Fork 39
/
cause_test.go
48 lines (42 loc) · 907 Bytes
/
cause_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
package stacktrace_test
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/palantir/stacktrace"
)
type customError string
func (e customError) Error() string { return string(e) }
func TestRootCause(t *testing.T) {
for _, test := range []struct {
err error
rootCause error
}{
{
err: nil,
rootCause: nil,
},
{
err: errors.New("msg"),
rootCause: errors.New("msg"),
},
{
err: stacktrace.NewError("msg"),
rootCause: errors.New("msg"),
},
{
err: stacktrace.Propagate(stacktrace.NewError("msg1"), "msg2"),
rootCause: errors.New("msg1"),
},
{
err: customError("msg"),
rootCause: customError("msg"),
},
{
err: stacktrace.Propagate(customError("msg1"), "msg2"),
rootCause: customError("msg1"),
},
} {
assert.Equal(t, test.rootCause, stacktrace.RootCause(test.err))
}
}