MCPcopy
hub / github.com/gofiber/fiber / TestRemoveRoute

Function TestRemoveRoute

router_test.go:1327–1469  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1325}
1326
1327func TestRemoveRoute(t *testing.T) {
1328 app := New()
1329
1330 var buf strings.Builder
1331
1332 app.Use(func(c Ctx) error {
1333 buf.WriteString("1") //nolint:errcheck // not needed
1334 return c.Next()
1335 })
1336
1337 app.Post("/", func(c Ctx) error {
1338 buf.WriteString("2") //nolint:errcheck // not needed
1339 return c.SendStatus(StatusOK)
1340 })
1341
1342 app.Use("/test", func(c Ctx) error {
1343 buf.WriteString("3") //nolint:errcheck // not needed
1344 return c.Next()
1345 })
1346
1347 app.Get("/test", func(c Ctx) error {
1348 buf.WriteString("4") //nolint:errcheck // not needed
1349 return c.SendStatus(StatusOK)
1350 })
1351
1352 app.Post("/test", func(c Ctx) error {
1353 buf.WriteString("5") //nolint:errcheck // not needed
1354 return c.SendStatus(StatusOK)
1355 })
1356
1357 app.startupProcess()
1358
1359 require.Equal(t, uint32(6), app.handlersCount)
1360
1361 req, err := http.NewRequestWithContext(context.Background(), MethodPost, "/", http.NoBody)
1362 require.NoError(t, err)
1363
1364 resp, err := app.Test(req)
1365 require.NoError(t, err)
1366
1367 require.Equal(t, 200, resp.StatusCode)
1368 require.Equal(t, "12", buf.String())
1369
1370 buf.Reset()
1371
1372 req, err = http.NewRequestWithContext(context.Background(), MethodGet, "/test", http.NoBody)
1373 require.NoError(t, err)
1374
1375 resp, err = app.Test(req)
1376 require.NoError(t, err)
1377
1378 require.Equal(t, 200, resp.StatusCode)
1379 require.Equal(t, "134", buf.String())
1380
1381 buf.Reset()
1382
1383 require.Equal(t, uint32(6), app.handlersCount)
1384

Callers

nothing calls this directly

Calls 15

startupProcessMethod · 0.80
TestMethod · 0.80
RemoveRouteMethod · 0.80
RebuildTreeMethod · 0.80
RemoveRouteFuncMethod · 0.80
NewFunction · 0.70
UseMethod · 0.65
WriteStringMethod · 0.65
NextMethod · 0.65
PostMethod · 0.65
SendStatusMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected