-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheventID_test.go
68 lines (53 loc) · 2.05 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
package sentry
import (
"log"
"testing"
"github.com/stretchr/testify/assert"
)
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) {
id, err := NewEventID()
assert.Nil(t, err, "creating an event ID shouldn't return an error")
assert.Regexp(t, "^[0-9a-f]{32}$", id, "the event ID should be 32 characters long and only alphanumeric characters")
t.Run("EventID()", func(t *testing.T) {
assert.Nil(t, EventID("invalid"), "it should return nil if the ID has the wrong length")
assert.Nil(t, EventID("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), "it should return nil if the ID contains invalid characters")
o := EventID(id)
assert.NotNil(t, o, "it should return a non-nil option if the ID is valid")
assert.Implements(t, (*Option)(nil), o, "it should implement the Option interface")
assert.Equal(t, "event_id", o.Class(), "it should use the correct option class")
t.Run("MarshalJSON()", func(t *testing.T) {
assert.Equal(t, id, testOptionsSerialize(t, EventID(id)), "it should serialize to the ID")
})
})
t.Run("Packet Extensions", func(t *testing.T) {
t.Run("getEventID()", func(t *testing.T) {
p := NewPacket()
assert.NotNil(t, p, "the packet should not be nil")
pp, ok := p.(*packet)
assert.True(t, ok, "the packet should actually be a *packet")
assert.Equal(t, "", pp.getEventID(), "it should return an empty event ID if there is no EventID option")
p = NewPacket().SetOptions(EventID(id))
assert.NotNil(t, p, "the packet should not be nil")
pp, ok = p.(*packet)
assert.True(t, ok, "the packet should actually be a *packet")
assert.Equal(t, id, pp.getEventID(), "it should return the event ID")
})
})
}