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

Function Test_App_Use_StrictRouting

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

Source from the content-addressed store, hash-verified

1016}
1017
1018func Test_App_Use_StrictRouting(t *testing.T) {
1019 t.Parallel()
1020 app := New(Config{StrictRouting: true})
1021
1022 app.Get("/abc", func(c Ctx) error {
1023 return c.SendString(c.Path())
1024 })
1025
1026 g := app.Group("/foo")
1027 g.Get("/", func(c Ctx) error {
1028 return c.SendString(c.Path())
1029 })
1030
1031 // wrong path in the requested route -> 404
1032 resp, err := app.Test(httptest.NewRequest(MethodGet, "/abc/", http.NoBody))
1033 require.NoError(t, err, "app.Test(req)")
1034 require.Equal(t, StatusNotFound, resp.StatusCode, "Status code")
1035
1036 // right path in the requested route -> 200
1037 resp, err = app.Test(httptest.NewRequest(MethodGet, "/abc", http.NoBody))
1038 require.NoError(t, err, "app.Test(req)")
1039 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
1040
1041 // wrong path with group in the requested route -> 404
1042 resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo", http.NoBody))
1043 require.NoError(t, err, "app.Test(req)")
1044 require.Equal(t, StatusNotFound, resp.StatusCode, "Status code")
1045
1046 // right path with group in the requested route -> 200
1047 resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/", http.NoBody))
1048 require.NoError(t, err, "app.Test(req)")
1049 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
1050}
1051
1052func Test_App_Add_Method_Test(t *testing.T) {
1053 t.Parallel()

Callers

nothing calls this directly

Calls 6

TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SendStringMethod · 0.65
PathMethod · 0.65
GroupMethod · 0.65

Tested by

no test coverage detected