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

Function Test_App_Use_CaseSensitive

app_test.go:888–917  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

886}
887
888func Test_App_Use_CaseSensitive(t *testing.T) {
889 t.Parallel()
890 app := New(Config{CaseSensitive: true})
891
892 app.Use("/abc", func(c Ctx) error {
893 return c.SendString(c.Path())
894 })
895
896 // wrong letters in the requested route -> 404
897 resp, err := app.Test(httptest.NewRequest(MethodGet, "/AbC", http.NoBody))
898 require.NoError(t, err, "app.Test(req)")
899 require.Equal(t, StatusNotFound, resp.StatusCode, "Status code")
900
901 // right letters in the requested route -> 200
902 resp, err = app.Test(httptest.NewRequest(MethodGet, "/abc", http.NoBody))
903 require.NoError(t, err, "app.Test(req)")
904 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
905
906 // check the detected path when the case-insensitive recognition is activated
907 app.config.CaseSensitive = false
908 // check the case-sensitive feature
909 resp, err = app.Test(httptest.NewRequest(MethodGet, "/AbC", http.NoBody))
910 require.NoError(t, err, "app.Test(req)")
911 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
912
913 body, err := io.ReadAll(resp.Body)
914 require.NoError(t, err, "app.Test(req)")
915 // check the detected path result
916 require.Equal(t, "/AbC", app.toString(body))
917}
918
919func Test_App_Not_Use_StrictRouting(t *testing.T) {
920 t.Parallel()

Callers

nothing calls this directly

Calls 6

TestMethod · 0.80
toStringMethod · 0.80
NewFunction · 0.70
UseMethod · 0.65
SendStringMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected