-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathevent_test.go
47 lines (35 loc) · 960 Bytes
/
event_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
package event
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEventToString(t *testing.T) {
t.Parallel()
t.Run("Event with description", func(t *testing.T) {
t.Parallel()
s := String(RateLimitSmoothingUp)
assert.NotEmpty(t, s)
assert.Contains(t, s, " ")
})
t.Run("Event without description", func(t *testing.T) {
t.Parallel()
s := String(Event("invalid"))
assert.Equal(t, "invalid", s)
})
}
func TestAddEventToRequest(t *testing.T) {
t.Parallel()
req, err := http.NewRequestWithContext(context.Background(), "GET", "http://example.com", nil)
assert.NoError(t, err)
// Test adding events to the request context
Add(req, TokenDeleted)
Add(req, RateLimitExceeded)
// Get events from request context
events := Get(req.Context())
// Expect the two events we added
assert.Len(t, events, 2)
assert.Contains(t, events, TokenDeleted)
assert.Contains(t, events, RateLimitExceeded)
}