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

Function Test_Middleware_Route_Naming_With_Use

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

Source from the content-addressed store, hash-verified

3141}
3142
3143func Test_Middleware_Route_Naming_With_Use(t *testing.T) {
3144 t.Parallel()
3145 named := "named"
3146 app := New()
3147
3148 app.Get("/unnamed", func(c Ctx) error {
3149 return c.Next()
3150 })
3151
3152 app.Post("/named", func(c Ctx) error {
3153 return c.Next()
3154 }).Name(named)
3155
3156 app.Use(func(c Ctx) error {
3157 return c.Next()
3158 }) // no name - logging MW
3159
3160 app.Use(func(c Ctx) error {
3161 return c.Next()
3162 }).Name("corsMW")
3163
3164 app.Use(func(c Ctx) error {
3165 return c.Next()
3166 }).Name("compressMW")
3167
3168 app.Use(func(c Ctx) error {
3169 return c.Next()
3170 }) // no name - cache MW
3171
3172 grp := app.Group("/pages").Name("pages.")
3173 grp.Use(func(c Ctx) error {
3174 return c.Next()
3175 }).Name("csrfMW")
3176
3177 grp.Get("/home", func(c Ctx) error {
3178 return c.Next()
3179 }).Name("home")
3180
3181 grp.Get("/unnamed", func(c Ctx) error {
3182 return c.Next()
3183 })
3184
3185 for _, route := range app.GetRoutes() {
3186 switch route.Path {
3187 case "/":
3188 require.Equal(t, "compressMW", route.Name)
3189 case "/unnamed", "/pages/unnamed":
3190 require.Empty(t, route.Name)
3191 case "/named":
3192 require.Equal(t, named, route.Name)
3193 case "/pages":
3194 require.Equal(t, "pages.csrfMW", route.Name)
3195 case "/pages/home":
3196 require.Equal(t, "pages.home", route.Name)
3197 default:
3198 t.Errorf("unknown route: %s", route.Path)
3199 }
3200 }

Callers

nothing calls this directly

Calls 9

GetRoutesMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
NextMethod · 0.65
NameMethod · 0.65
PostMethod · 0.65
UseMethod · 0.65
GroupMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected