-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
stacktrace_test.go
63 lines (48 loc) · 1.06 KB
/
stacktrace_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
package oops
import (
"runtime/debug"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func a() *oopsStacktrace {
return b()
}
func b() *oopsStacktrace {
return c()
}
func c() *oopsStacktrace {
return d()
}
func d() *oopsStacktrace {
return e()
}
func e() *oopsStacktrace {
return f()
}
func f() *oopsStacktrace {
return newStacktrace("1234")
}
func TestStacktrace(t *testing.T) {
is := assert.New(t)
st := a()
is.NotNil(st)
is.Equal("1234", st.span)
bi, ok := debug.ReadBuildInfo()
is.True(ok)
if st.frames != nil {
for _, f := range st.frames {
is.Truef(strings.Contains(f.file, bi.Path), "frame file %s should contain %s", f.file, bi.Path)
}
is.Len(st.frames, 7, "expected 7 frames")
if len(st.frames) == 7 {
is.Equal("f", (st.frames)[0].function)
is.Equal("e", (st.frames)[1].function)
is.Equal("d", (st.frames)[2].function)
is.Equal("c", (st.frames)[3].function)
is.Equal("b", (st.frames)[4].function)
is.Equal("a", (st.frames)[5].function)
is.Equal("TestStacktrace", (st.frames)[6].function)
}
}
}