File: stack_test.go

package info (click to toggle)
golang-github-stvp-roll 0.0~git20170522.3627a5c-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84 kB
  • sloc: makefile: 2
file content (102 lines) | stat: -rw-r--r-- 1,999 bytes parent folder | download | duplicates (4)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package roll

import (
	"strings"
	"testing"
)

func TestBuildRollbarFrames(t *testing.T) {
	frames := buildRollbarFrames(getCallers(0))

	if len(frames) != 4 {
		t.Fatalf("expected 4 frames, got %d", len(frames))
	}

	if !strings.Contains(frames[0].Filename, "github.com/stvp/roll/stack.go") {
		t.Errorf("expected %#v, got %#v", "github.com/stvp/roll/stack.go", frames[0].Filename)
	}

	if !strings.Contains(frames[0].Method, "roll.getCallers") {
		t.Errorf("expected %#v, got %#v", "roll.getCallers", frames[0].Method)
	}
}

func TestRollbarFramesFingerprint(t *testing.T) {
	tests := []struct {
		Fingerprint string
		Title       string
		Frames      rollbarFrames
	}{
		{
			"9344290d",
			"broken",
			rollbarFrames{
				{"foo.go", "Oops", 1},
			},
		},
		{
			"9344290d",
			"very broken",
			rollbarFrames{
				{"foo.go", "Oops", 1},
			},
		},
		{
			"a4d78b7",
			"broken",
			rollbarFrames{
				{"foo.go", "Oops", 2},
			},
		},
		{
			"50e0fcb3",
			"broken",
			rollbarFrames{
				{"foo.go", "Oops", 1},
				{"foo.go", "Oops", 2},
			},
		},
	}

	for i, test := range tests {
		fp := test.Frames.fingerprint()
		if fp != test.Fingerprint {
			t.Errorf("tests[%d]: got %s", i, fp)
		}
	}
}

func TestScrubFile(t *testing.T) {
	tests := []struct {
		Given    string
		Expected string
	}{
		{"", ""},
		{"foo.go", "foo.go"},
		{"/home/foo/go/src/github.com/stvp/rollbar.go", "github.com/stvp/rollbar.go"},
		{"/home/foo/go/src/gopkg.in/yaml.v1/encode.go", "gopkg.in/yaml.v1/encode.go"},
	}
	for i, test := range tests {
		got := scrubFile(test.Given)
		if got != test.Expected {
			t.Errorf("tests[%d]: got %s", i, got)
		}
	}
}

func TestScrubFunction(t *testing.T) {
	tests := []struct {
		Given    string
		Expected string
	}{
		{"", ""},
		{"roll.getCallers", "roll.getCallers"},
		{"github.com/stvp/roll.getCallers", "roll.getCallers"},
	}
	for i, test := range tests {
		got := scrubFunction(test.Given)
		if got != test.Expected {
			t.Errorf("tests[%d]: got %s", i, got)
		}
	}
}