forked from bugsnag/bugsnag-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_test.go
37 lines (32 loc) · 903 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
package bugsnag
import (
"context"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"
)
func TestPopulateEvent(t *testing.T) {
event := new(Event)
contexts := make(chan context.Context, 1)
reqs := make(chan *http.Request, 1)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
contexts <- AttachRequestData(r.Context(), r)
reqs <- r
}))
defer ts.Close()
http.Get(ts.URL + "/serenity?q=abcdef")
ctx, req := <-contexts, <-reqs
populateEventWithContext(ctx, event)
for _, tc := range []struct{ e, c interface{} }{
{e: event.Ctx, c: ctx},
{e: event.Request, c: extractRequestInfoFromReq(req)},
{e: event.Context, c: req.URL.Path},
{e: event.User.Id, c: req.RemoteAddr[:strings.LastIndex(req.RemoteAddr, ":")]},
} {
if !reflect.DeepEqual(tc.e, tc.c) {
t.Errorf("Expected '%+v' and '%+v' to be equal", tc.e, tc.c)
}
}
}