-
Notifications
You must be signed in to change notification settings - Fork 23
/
stack_test.go
72 lines (66 loc) · 1.32 KB
/
stack_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
package rollbar
import (
"strings"
"testing"
)
func TestBuildStack(t *testing.T) {
frame := buildStack(getCallersFrames(0))[0]
if !strings.HasSuffix(frame.Filename, "rollbar-go/stack_test.go") {
t.Errorf("got: %s", frame.Filename)
}
if frame.Method != "rollbar-go.TestBuildStack" {
t.Errorf("got: %s", frame.Method)
}
if frame.Line != 9 {
t.Errorf("got: %d", frame.Line)
}
}
func TestStackFingerprint(t *testing.T) {
tests := []struct {
Fingerprint string
Stack stack
}{
{
"9344290d",
stack{
frame{"foo.go", "Oops", 1},
},
},
{
"a4d78b7",
stack{
frame{"foo.go", "Oops", 2},
},
},
{
"50e0fcb3",
stack{
frame{"foo.go", "Oops", 1},
frame{"foo.go", "Oops", 2},
},
},
}
for i, test := range tests {
fingerprint := test.Stack.Fingerprint()
if fingerprint != test.Fingerprint {
t.Errorf("tests[%d]: got %s", i, fingerprint)
}
}
}
func TestShortenFilePath(t *testing.T) {
tests := []struct {
Given string
Expected string
}{
{"", ""},
{"foo.go", "foo.go"},
{"/usr/local/go/src/pkg/runtime/proc.c", "pkg/runtime/proc.c"},
{"/home/foo/go/src/github.com/stvp/rollbar.go", "github.com/stvp/rollbar.go"},
}
for i, test := range tests {
got := shortenFilePath(test.Given)
if got != test.Expected {
t.Errorf("tests[%d]: got %s", i, got)
}
}
}