MCPcopy Index your code
hub / github.com/labstack/echo / TestRateLimiterWithConfig_skipper

Function TestRateLimiterWithConfig_skipper

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

Source from the content-addressed store, hash-verified

226}
227
228func TestRateLimiterWithConfig_skipper(t *testing.T) {
229 e := echo.New()
230
231 var beforeFuncRan bool
232 handler := func(c *echo.Context) error {
233 return c.String(http.StatusOK, "test")
234 }
235 var inMemoryStore = NewRateLimiterMemoryStore(5)
236
237 req := httptest.NewRequest(http.MethodGet, "/", nil)
238 req.Header.Add(echo.HeaderXRealIP, "127.0.0.1")
239
240 rec := httptest.NewRecorder()
241
242 c := e.NewContext(req, rec)
243
244 mw, err := RateLimiterConfig{
245 Skipper: func(c *echo.Context) bool {
246 return true
247 },
248 BeforeFunc: func(c *echo.Context) {
249 beforeFuncRan = true
250 },
251 Store: inMemoryStore,
252 IdentifierExtractor: func(ctx *echo.Context) (string, error) {
253 return "127.0.0.1", nil
254 },
255 }.ToMiddleware()
256 assert.NoError(t, err)
257
258 err = mw(handler)(c)
259
260 assert.NoError(t, err)
261 assert.Equal(t, false, beforeFuncRan)
262}
263
264func TestRateLimiterWithConfig_skipperNoSkip(t *testing.T) {
265 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…