...
1 package emperror
2
3 import (
4 stderrors "errors"
5 "testing"
6
7 "github.com/pkg/errors"
8 )
9
10 func TestStackTrace(t *testing.T) {
11 err := errors.WithMessage(errors.New("error"), "wrapper")
12
13 stack, ok := StackTrace(err)
14 if !ok {
15 t.Fatal("stack trace is missing")
16 }
17
18 if stack == nil {
19 t.Error("empty stack trace")
20 }
21 }
22
23 func TestExposeStackTrace(t *testing.T) {
24 err := errors.WithMessage(errors.New("error"), "wrapper")
25
26 err = ExposeStackTrace(err)
27
28 stack := err.(stackTracer).StackTrace()
29
30 if len(stack) < 1 {
31 t.Error("empty stack trace")
32 }
33 }
34
35 func TestExposeStackTrace_NoStackTrace(t *testing.T) {
36 err := stderrors.New("error")
37
38 serr := ExposeStackTrace(err)
39
40 if got, want := serr, err; got != want {
41 t.Errorf("error does not match the expected one\nactual: %s\nexpected: %s", got, want)
42 }
43 }
44
View as plain text