...
1 package airbrakehandler
2
3 import (
4 "net/http"
5 "os"
6 "strconv"
7 "testing"
8 "time"
9
10 "github.com/airbrake/gobrake"
11 "github.com/pkg/errors"
12
13 "github.com/goph/emperror"
14 "github.com/goph/emperror/httperr"
15 )
16
17 func newHandler(t *testing.T) *Handler {
18 host := os.Getenv("AIRBRAKE_HOST")
19 projectID, _ := strconv.Atoi(os.Getenv("AIRBRAKE_PROJECT_ID"))
20 projectKey := os.Getenv("AIRBRAKE_PROJECT_KEY")
21
22 if host == "" || projectID == 0 || projectKey == "" {
23 t.Skip("missing airbrake credentials")
24 }
25
26 return NewFromNotifier(gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
27 ProjectId: int64(projectID),
28 ProjectKey: projectKey,
29 Host: host,
30 }))
31 }
32
33 func TestIntegration_Handler(t *testing.T) {
34 handler := newHandler(t)
35 defer handler.Close()
36
37 err := errors.New("error")
38
39 handler.Handle(err)
40
41
42 time.Sleep(500 * time.Millisecond)
43 }
44
45 func TestIntegration_WithContext(t *testing.T) {
46 handler := newHandler(t)
47 defer handler.Close()
48
49 err := emperror.With(errors.New("error with context"), "key", "value")
50
51 handler.Handle(err)
52
53
54 time.Sleep(500 * time.Millisecond)
55 }
56
57 func TestIntegration_WithHTTPRequest(t *testing.T) {
58 handler := newHandler(t)
59 defer handler.Close()
60
61 req, e := http.NewRequest("GET", "https://google.com", nil)
62 if e != nil {
63 t.Fatal(e)
64 }
65
66 err := httperr.WithHTTPRequest(errors.New("error with http request"), req)
67
68 handler.Handle(err)
69
70
71 time.Sleep(500 * time.Millisecond)
72 }
73
View as plain text