MCPcopy
hub / github.com/labstack/echo / TestRateLimiterWithConfig_skipperNoSkip

Function TestRateLimiterWithConfig_skipperNoSkip

middleware/rate_limiter_test.go:264–297  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

262}
263
264func TestRateLimiterWithConfig_skipperNoSkip(t *testing.T) {
265 e := echo.New()
266
267 var beforeFuncRan bool
268 handler := func(c *echo.Context) error {
269 return c.String(http.StatusOK, "test")
270 }
271 var inMemoryStore = NewRateLimiterMemoryStore(5)
272
273 req := httptest.NewRequest(http.MethodGet, "/", nil)
274 req.Header.Add(echo.HeaderXRealIP, "127.0.0.1")
275
276 rec := httptest.NewRecorder()
277
278 c := e.NewContext(req, rec)
279
280 mw, err := RateLimiterConfig{
281 Skipper: func(c *echo.Context) bool {
282 return false
283 },
284 BeforeFunc: func(c *echo.Context) {
285 beforeFuncRan = true
286 },
287 Store: inMemoryStore,
288 IdentifierExtractor: func(ctx *echo.Context) (string, error) {
289 return "127.0.0.1", nil
290 },
291 }.ToMiddleware()
292 assert.NoError(t, err)
293
294 _ = mw(handler)(c)
295
296 assert.Equal(t, true, beforeFuncRan)
297}
298
299func TestRateLimiterWithConfig_beforeFunc(t *testing.T) {
300 e := echo.New()

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
NewContextMethod · 0.80
AddMethod · 0.65
ToMiddlewareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…