Skip to content

Commit

Permalink
Added testing for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Sep 7, 2023
1 parent 7f56709 commit de5ca15
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions v3/newrelic/internal_17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ func myErrorHandler(w http.ResponseWriter, req *http.Request) {
txn.NoticeError(myError{})
}

func myErrorHandlerFastHTTP(ctx *fasthttp.RequestCtx) {
ctx.WriteString("noticing an error")
txn := ctx.UserValue("transaction").(*Transaction)
txn.NoticeError(myError{})
}

func TestWrapHandleFastHTTPFunc(t *testing.T) {
app := testApp(nil, ConfigDistributedTracerEnabled(true), t)

// Define your handler
handler := func(ctx *fasthttp.RequestCtx) {
ctx.WriteString("Hello World")
}

_, wrappedHandler := WrapHandleFuncFastHTTP(app.Application, "/hello", handler)
_, wrappedHandler := WrapHandleFuncFastHTTP(app.Application, "/hello", myErrorHandlerFastHTTP)

if wrappedHandler == nil {
t.Error("Error when creating a wrapped handler")
Expand All @@ -36,6 +37,11 @@ func TestWrapHandleFastHTTPFunc(t *testing.T) {
ctx.Request.Header.SetMethod("GET")
ctx.Request.SetRequestURI("/hello")
wrappedHandler(ctx)
app.ExpectErrors(t, []internal.WantError{{
TxnName: "WebTransaction/Go/GET /hello",
Msg: "my msg",
Klass: "newrelic.myError",
}})

app.ExpectMetrics(t, []internal.WantMetric{
{Name: "WebTransaction/Go/GET /hello", Scope: "", Forced: true, Data: nil},
Expand All @@ -47,6 +53,11 @@ func TestWrapHandleFastHTTPFunc(t *testing.T) {
{Name: "Apdex/Go/GET /hello", Scope: "", Forced: false, Data: nil},
{Name: "DurationByCaller/Unknown/Unknown/Unknown/Unknown/all", Scope: "", Forced: false, Data: nil},
{Name: "DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb", Scope: "", Forced: false, Data: nil},
{Name: "Errors/all", Scope: "", Forced: true, Data: singleCount},
{Name: "Errors/allWeb", Scope: "", Forced: true, Data: singleCount},
{Name: "Errors/WebTransaction/Go/GET /hello", Scope: "", Forced: true, Data: singleCount},
{Name: "ErrorsByCaller/Unknown/Unknown/Unknown/Unknown/all", Scope: "", Forced: false, Data: nil},
{Name: "ErrorsByCaller/Unknown/Unknown/Unknown/Unknown/allWeb", Scope: "", Forced: false, Data: nil},
})
}

Expand Down

0 comments on commit de5ca15

Please sign in to comment.