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

Function Test_Route_Match_Star

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

Source from the content-addressed store, hash-verified

249}
250
251func Test_Route_Match_Star(t *testing.T) {
252 t.Parallel()
253
254 app := New()
255
256 app.Get("/*", func(c Ctx) error {
257 return c.SendString(c.Params("*"))
258 })
259
260 resp, err := app.Test(httptest.NewRequest(MethodGet, "/*", http.NoBody))
261 require.NoError(t, err, "app.Test(req)")
262 require.Equal(t, 200, resp.StatusCode, "Status code")
263
264 body, err := io.ReadAll(resp.Body)
265 require.NoError(t, err, "app.Test(req)")
266 require.Equal(t, "*", app.toString(body))
267
268 // with param
269 resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", http.NoBody))
270 require.NoError(t, err, "app.Test(req)")
271 require.Equal(t, 200, resp.StatusCode, "Status code")
272
273 body, err = io.ReadAll(resp.Body)
274 require.NoError(t, err, "app.Test(req)")
275 require.Equal(t, "test", app.toString(body))
276
277 // without parameter
278 route := Route{
279 star: true,
280 path: "/*",
281 routeParser: routeParser{},
282 }
283 params := [maxParams]string{}
284 match := route.match("", "", &params)
285 require.True(t, match)
286 require.Equal(t, [maxParams]string{}, params)
287
288 // with parameter
289 match = route.match("/favicon.ico", "/favicon.ico", &params)
290 require.True(t, match)
291 require.Equal(t, [maxParams]string{"favicon.ico"}, params)
292
293 // without parameter again
294 match = route.match("", "", &params)
295 require.True(t, match)
296 require.Equal(t, [maxParams]string{}, params)
297}
298
299func Test_Route_Match_Root(t *testing.T) {
300 t.Parallel()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected