...

Source file src/github.com/goph/emperror/handler/sentryhandler/handler_integration_test.go

Documentation: github.com/goph/emperror/handler/sentryhandler

     1  package sentryhandler
     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  	dsn := os.Getenv("SENTRY_DSN")
    17  
    18  	if dsn == "" {
    19  		t.Skip("missing sentry credentials")
    20  	}
    21  
    22  	handler, err := New(dsn)
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	return handler
    28  }
    29  
    30  func TestIntegration_Handler(t *testing.T) {
    31  	handler := newHandler(t)
    32  	defer handler.Close()
    33  
    34  	err := errors.New("error")
    35  
    36  	handler.Handle(err)
    37  
    38  	// Wait for the notice to reach the queue before closing
    39  	time.Sleep(500 * time.Millisecond)
    40  }
    41  
    42  func TestIntegration_WithContext(t *testing.T) {
    43  	handler := newHandler(t)
    44  	defer handler.Close()
    45  
    46  	err := emperror.With(errors.New("error with context"), "key", "value")
    47  
    48  	handler.Handle(err)
    49  
    50  	// Wait for the notice to reach the queue before closing
    51  	time.Sleep(500 * time.Millisecond)
    52  }
    53  
    54  func TestIntegration_WithHTTPRequest(t *testing.T) {
    55  	handler := newHandler(t)
    56  	defer handler.Close()
    57  
    58  	req, e := http.NewRequest("GET", "https://google.com", nil)
    59  	if e != nil {
    60  		t.Fatal(e)
    61  	}
    62  
    63  	err := httperr.WithHTTPRequest(errors.New("error with http request"), req)
    64  
    65  	handler.Handle(err)
    66  
    67  	// Wait for the notice to reach the queue before closing
    68  	time.Sleep(500 * time.Millisecond)
    69  }
    70  

View as plain text