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

Function Test_Route_Match_WithEscapeChar

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

Source from the content-addressed store, hash-verified

642}
643
644func Test_Route_Match_WithEscapeChar(t *testing.T) {
645 t.Parallel()
646
647 app := New()
648 // static route and escaped part
649 app.Get("/v1/some/resource/name\\:customVerb", func(c Ctx) error {
650 return c.SendString("static")
651 })
652 // group route
653 group := app.Group("/v2/\\:firstVerb")
654 group.Get("/\\:customVerb", func(c Ctx) error {
655 return c.SendString("group")
656 })
657 // route with resource param and escaped part
658 app.Get("/v3/:resource/name\\:customVerb", func(c Ctx) error {
659 return c.SendString(c.Params("resource"))
660 })
661
662 // check static route
663 resp, err := app.Test(httptest.NewRequest(MethodGet, "/v1/some/resource/name:customVerb", http.NoBody))
664 require.NoError(t, err, "app.Test(req)")
665 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
666
667 body, err := io.ReadAll(resp.Body)
668 require.NoError(t, err, "app.Test(req)")
669 require.Equal(t, "static", app.toString(body))
670
671 // check group route
672 resp, err = app.Test(httptest.NewRequest(MethodGet, "/v2/:firstVerb/:customVerb", http.NoBody))
673 require.NoError(t, err, "app.Test(req)")
674 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
675
676 body, err = io.ReadAll(resp.Body)
677 require.NoError(t, err, "app.Test(req)")
678 require.Equal(t, "group", app.toString(body))
679
680 // check param route
681 resp, err = app.Test(httptest.NewRequest(MethodGet, "/v3/awesome/name:customVerb", http.NoBody))
682 require.NoError(t, err, "app.Test(req)")
683 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
684
685 body, err = io.ReadAll(resp.Body)
686 require.NoError(t, err, "app.Test(req)")
687 require.Equal(t, "awesome", app.toString(body))
688}
689
690func Test_Route_Match_Middleware_HasPrefix(t *testing.T) {
691 t.Parallel()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected