-
Notifications
You must be signed in to change notification settings - Fork 16
/
notice_test.go
74 lines (61 loc) · 2.01 KB
/
notice_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
73
74
package honeybadger
import (
"encoding/json"
"errors"
"testing"
)
func newTestError() Error {
var frames []*Frame
frames = append(frames, &Frame{
File: "/path/to/root/badgers.go",
Number: "1",
Method: "badgers",
})
frames = append(frames, &Frame{
File: "/foo/bar/baz.go",
Number: "2",
Method: "baz",
})
return Error{
err: errors.New("Cobras!"),
Message: "Cobras!",
Class: "honeybadger",
Stack: frames,
}
}
func TestNewNotice(t *testing.T) {
err := newTestError()
var notice *Notice
notice = newNotice(&Configuration{Root: "/path/to/root"}, err)
if notice.ErrorMessage != "Cobras!" {
t.Errorf("Unexpected value for notice.ErrorMessage. expected=%#v result=%#v", "Cobras!", notice.ErrorMessage)
}
if notice.Error.err != err.err {
t.Errorf("Unexpected value for notice.Error. expected=%#v result=%#v", err.err, notice.Error.err)
}
if notice.Backtrace[0].File != "[PROJECT_ROOT]/badgers.go" {
t.Errorf("Expected notice to substitute project root. expected=%#v result=%#v", "[PROJECT_ROOT]/badgers.go", notice.Backtrace[0].File)
}
if notice.Backtrace[1].File != "/foo/bar/baz.go" {
t.Errorf("Expected notice not to trash non-project file. expected=%#v result=%#v", "/foo/bar/baz.go", notice.Backtrace[1].File)
}
notice = newNotice(&Configuration{Root: ""}, err)
if notice.Backtrace[0].File != "/path/to/root/badgers.go" {
t.Errorf("Expected notice not to trash project root. expected=%#v result=%#v", "/path/to/root/badgers.go", notice.Backtrace[0].File)
}
notice = newNotice(&Configuration{}, err, Context{"foo": "bar"})
if notice.Context["foo"] != "bar" {
t.Errorf("Expected notice to contain context. expected=%#v result=%#v", "bar", notice.Context["foo"])
}
}
func TestToJSON(t *testing.T) {
notice := newNotice(Config, newError(errors.New("Cobras!"), 0))
raw := notice.toJSON()
var payload hash
err := json.Unmarshal(raw, &payload)
if err != nil {
t.Errorf("Got error while parsing notice JSON err=%#v json=%#v", err, raw)
return
}
testNoticePayload(t, payload)
}