-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
47 lines (36 loc) · 901 Bytes
/
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
package slogbugsnag
import (
"runtime"
"testing"
perrors "github.com/pkg/errors"
)
func TestNewErrorWithStackNil(t *testing.T) {
t.Parallel()
pc, _, _, _ := runtime.Caller(1)
err := newErrorWithStack(nil, "oh no", pc+1)
if err == nil {
t.Fatal("expected non-nil error")
}
e, ok := err.(errorWithCallers)
if !ok {
t.Fatalf("expected errorWithCallers; Got: %T", err)
}
t.Log(e.String())
if e.Unwrap().Error() != "oh no" || e.Unwrap() != e.error || e.error.Error() != e.Error() {
t.Error("wrong error:", e.Unwrap().Error())
}
if len(e.Callers()) < 2 {
t.Error("expected larger stack")
}
}
func TestNewErrorWithStackExisting(t *testing.T) {
t.Parallel()
origErr := perrors.New("an error")
err := newErrorWithStack(origErr, "oh no", 0)
if err == nil {
t.Fatal("expected non-nil error")
}
if err != origErr {
t.Fatal("expected github.com/pkg/errors error")
}
}