forked from SierraSoftworks/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventID_test.go
91 lines (72 loc) · 1.92 KB
/
eventID_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package sentry
import (
"log"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func ExampleEventID() {
id, err := NewEventID()
if err != nil {
log.Fatalln(err)
}
cl := NewClient()
ctxCl := cl.With(
// You could set the event ID for a context specific
// client if you wanted (but you probably shouldn't).
EventID(id),
)
ctxCl.Capture(
// The best place to set it is when you are ready to send
// an event to Sentry.
EventID(id),
)
}
func TestEventID(t *testing.T) {
Convey("EventID", t, func() {
Convey("NewEventID()", func() {
Convey("Should return a valid event ID", func() {
id, err := NewEventID()
So(err, ShouldBeNil)
So(id, ShouldHaveLength, 32)
for _, r := range id {
So(r, ShouldBeIn, []rune("0123456789abcdef"))
}
})
})
id, err := NewEventID()
So(err, ShouldBeNil)
Convey("EventID()", func() {
id, err := NewEventID()
So(err, ShouldBeNil)
Convey("Should return an Option", func() {
So(EventID(id), ShouldImplement, (*Option)(nil))
})
Convey("Should return nil if the ID is invalid", func() {
So(EventID("invalid"), ShouldBeNil)
So(EventID("xx23456789abcdef0123456789abcdef"), ShouldBeNil)
})
})
Convey("Should use the correct class", func() {
So(EventID(id).Class(), ShouldEqual, "event_id")
})
Convey("MarshalJSON", func() {
So(testOptionsSerialize(EventID(id)), ShouldResemble, id)
})
Convey("Packet Extensions", func() {
Convey("getEventID()", func() {
Convey("With an EventID", func() {
p := NewPacket().SetOptions(EventID(id))
pp, ok := p.(*packet)
So(ok, ShouldBeTrue)
So(pp.getEventID(), ShouldEqual, id)
})
Convey("Without an EventID", func() {
p := NewPacket()
pp, ok := p.(*packet)
So(ok, ShouldBeTrue)
So(pp.getEventID(), ShouldEqual, "")
})
})
})
})
}