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

Function Test_App_Use_MultiplePrefix

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

Source from the content-addressed store, hash-verified

951}
952
953func Test_App_Use_MultiplePrefix(t *testing.T) {
954 t.Parallel()
955 app := New()
956
957 app.Use([]string{"/john", "/doe"}, func(c Ctx) error {
958 return c.SendString(c.Path())
959 })
960
961 g := app.Group("/test")
962 g.Use([]string{"/john", "/doe"}, func(c Ctx) error {
963 return c.SendString(c.Path())
964 })
965
966 resp, err := app.Test(httptest.NewRequest(MethodGet, "/john", http.NoBody))
967 require.NoError(t, err, "app.Test(req)")
968 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
969
970 body, err := io.ReadAll(resp.Body)
971 require.NoError(t, err)
972 require.Equal(t, "/john", string(body))
973
974 resp, err = app.Test(httptest.NewRequest(MethodGet, "/doe", http.NoBody))
975 require.NoError(t, err, "app.Test(req)")
976 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
977
978 body, err = io.ReadAll(resp.Body)
979 require.NoError(t, err)
980 require.Equal(t, "/doe", string(body))
981
982 resp, err = app.Test(httptest.NewRequest(MethodGet, "/test/john", http.NoBody))
983 require.NoError(t, err, "app.Test(req)")
984 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
985
986 body, err = io.ReadAll(resp.Body)
987 require.NoError(t, err)
988 require.Equal(t, "/test/john", string(body))
989
990 resp, err = app.Test(httptest.NewRequest(MethodGet, "/test/doe", http.NoBody))
991 require.NoError(t, err, "app.Test(req)")
992 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
993
994 body, err = io.ReadAll(resp.Body)
995 require.NoError(t, err)
996 require.Equal(t, "/test/doe", string(body))
997}
998
999func Test_Group_Use_NoBoundary(t *testing.T) {
1000 t.Parallel()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected