...

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

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

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

View as plain text