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

Function Test_Route_Match_Parser

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

Source from the content-addressed store, hash-verified

315}
316
317func Test_Route_Match_Parser(t *testing.T) {
318 t.Parallel()
319
320 app := New()
321
322 app.Get("/foo/:ParamName", func(c Ctx) error {
323 return c.SendString(c.Params("ParamName"))
324 })
325 app.Get("/Foobar/*", func(c Ctx) error {
326 return c.SendString(c.Params("*"))
327 })
328 resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/bar", http.NoBody))
329 require.NoError(t, err, "app.Test(req)")
330 require.Equal(t, 200, resp.StatusCode, "Status code")
331
332 body, err := io.ReadAll(resp.Body)
333 require.NoError(t, err, "app.Test(req)")
334 require.Equal(t, "bar", app.toString(body))
335
336 // with star
337 resp, err = app.Test(httptest.NewRequest(MethodGet, "/Foobar/test", http.NoBody))
338 require.NoError(t, err, "app.Test(req)")
339 require.Equal(t, 200, resp.StatusCode, "Status code")
340
341 body, err = io.ReadAll(resp.Body)
342 require.NoError(t, err, "app.Test(req)")
343 require.Equal(t, "test", app.toString(body))
344}
345
346func TestAutoRegisterHeadRoutes(t *testing.T) {
347 t.Parallel()

Callers

nothing calls this directly

Calls 6

TestMethod · 0.80
toStringMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SendStringMethod · 0.65
ParamsMethod · 0.65

Tested by

no test coverage detected