-
Notifications
You must be signed in to change notification settings - Fork 2
/
raygun_test.go
74 lines (57 loc) · 1.55 KB
/
raygun_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package raygun_test
import (
"errors"
"testing"
"github.com/codeclysm/raygun"
jujuerr "github.com/juju/errors"
pkerr "github.com/pkg/errors"
)
type custErr string
func (e custErr) Error() string {
return string(e)
}
func (e custErr) Cause() error {
return errors.New("cause of: " + e.Error())
}
func TestFromErr(t *testing.T) {
var err error
var rayErr raygun.Error
// pkg/errors
err = pkerr.New("new error")
rayErr = raygun.FromErr(wrapErr(err))
if rayErr.Message != "wrapped err: new error" {
t.Error("rayErr.Message should be 'wrapped err: new error'")
}
if rayErr.InnerError != "new error" {
t.Error("rayErr.InnerError should be 'new error'")
}
if len(rayErr.StackTrace) != 4 {
t.Error("rayErr.StackTrace should be 4 elements long")
}
// juju/errors
err = jujuerr.New("new error")
rayErr = raygun.FromErr(annotateErr(err))
if rayErr.Message != "wrapped err: new error" {
t.Error("rayErr.Message should be 'wrapped err: new error'")
}
if rayErr.InnerError != "new error" {
t.Error("rayErr.InnerError should be 'new error'")
}
if len(rayErr.StackTrace) != 2 {
t.Error("rayErr.StackTrace should be 2 elements long")
}
// standard error
rayErr = raygun.FromErr(errors.New("new error"))
if rayErr.Message != "new error" {
t.Error("rayErr.Message should be 'new error'")
}
if len(rayErr.StackTrace) != 3 {
t.Error("rayErr.StackTrace should be 4 elements long")
}
}
func wrapErr(err error) error {
return pkerr.Wrap(err, "wrapped err")
}
func annotateErr(err error) error {
return jujuerr.Annotate(err, "wrapped err")
}