Skip to content

Commit

Permalink
add next test case in fibernewrelic
Browse files Browse the repository at this point in the history
  • Loading branch information
amantinetti committed Jul 3, 2024
1 parent 8a7d971 commit 6e643b2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions fibernewrelic/fiber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,70 @@ func TestNewrelicAppConfig(t *testing.T) {
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
assert.True(t, errorStatusCodeHandlerCalled)
})

t.Run("Jump Newrelic execution if next function is set",
func(t *testing.T) {
app := fiber.New()

cfg := Config{
License: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
AppName: "",
Enabled: true,
Next: func(c *fiber.Ctx) bool {
return c.OriginalURL() == "/jump"
},
}

newRelicApp, _ := newrelic.NewApplication(
newrelic.ConfigAppName(cfg.AppName),
newrelic.ConfigLicense(cfg.License),
newrelic.ConfigEnabled(cfg.Enabled),
)

cfg.Application = newRelicApp

app.Use(New(cfg))

app.Get("/jump", func(ctx *fiber.Ctx) error {
return ctx.SendStatus(200)
})

r := httptest.NewRequest("GET", "/jump", nil)
resp, _ := app.Test(r, -1)
assert.Equal(t, 200, resp.StatusCode)
})

t.Run("Continue Newrelic execution if next function is set",
func(t *testing.T) {
app := fiber.New()

cfg := Config{
License: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
AppName: "",
Enabled: true,
Next: func(c *fiber.Ctx) bool {
return c.OriginalURL() == "/jump"
},
}

newRelicApp, _ := newrelic.NewApplication(
newrelic.ConfigAppName(cfg.AppName),
newrelic.ConfigLicense(cfg.License),
newrelic.ConfigEnabled(cfg.Enabled),
)

cfg.Application = newRelicApp

app.Use(New(cfg))

app.Get("/", func(ctx *fiber.Ctx) error {
return ctx.SendStatus(200)
})

r := httptest.NewRequest("GET", "/", nil)
resp, _ := app.Test(r, -1)
assert.Equal(t, 200, resp.StatusCode)
})
}

func TestDefaultErrorStatusCodeHandler(t *testing.T) {
Expand Down

0 comments on commit 6e643b2

Please sign in to comment.