...
1 package rollbarhandler
2
3 import (
4 "net/http"
5 "os"
6 "testing"
7 "time"
8
9 "github.com/pkg/errors"
10
11 "github.com/goph/emperror"
12 "github.com/goph/emperror/httperr"
13 )
14
15 func newHandler(t *testing.T) *Handler {
16 token := os.Getenv("ROLLBAR_TOKEN")
17
18 if token == "" {
19 t.Skip("missing rollbar credentials")
20 }
21
22 return New(token, "test", "latest", "localhost", "github.com/goph/emperror")
23 }
24
25 func TestIntegration_Handler(t *testing.T) {
26 handler := newHandler(t)
27 defer handler.Close()
28
29 err := errors.New("error")
30
31 handler.Handle(err)
32
33
34 time.Sleep(500 * time.Millisecond)
35 }
36
37 func TestIntegration_WithContext(t *testing.T) {
38 handler := newHandler(t)
39 defer handler.Close()
40
41 err := emperror.With(errors.New("error with context"), "key", "value")
42
43 handler.Handle(err)
44
45
46 time.Sleep(500 * time.Millisecond)
47 }
48
49 func TestIntegration_WithHTTPRequest(t *testing.T) {
50 handler := newHandler(t)
51 defer handler.Close()
52
53 req, e := http.NewRequest("GET", "https://google.com", nil)
54 if e != nil {
55 t.Fatal(e)
56 }
57
58 err := httperr.WithHTTPRequest(errors.New("error with http request"), req)
59
60 handler.Handle(err)
61
62
63 time.Sleep(500 * time.Millisecond)
64 }
65
View as plain text