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

Function TestCacheStorageDeleteError

middleware/cache/cache_test.go:305–336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

303}
304
305func TestCacheStorageDeleteError(t *testing.T) {
306 t.Parallel()
307
308 storage := newFailingCacheStorage()
309 storage.errs["del|GET|/|q=|h=accept:|accept-encoding:|accept-language:"] = errors.New("boom")
310
311 // Use an obviously expired timestamp without relying on time-based conversions
312 expired := &item{exp: 1}
313 raw, err := expired.MarshalMsg(nil)
314 require.NoError(t, err)
315
316 storage.data["GET|/|q=|h=accept:|accept-encoding:|accept-language:"] = raw
317
318 var captured error
319 app := fiber.New(fiber.Config{
320 ErrorHandler: func(c fiber.Ctx, err error) error {
321 captured = err
322 return c.Status(fiber.StatusInternalServerError).SendString("storage failure")
323 },
324 })
325
326 app.Use(New(Config{Storage: storage, Expiration: time.Second}))
327 app.Get("/", func(c fiber.Ctx) error {
328 return c.SendString("ok")
329 })
330
331 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
332 require.NoError(t, err)
333 require.Equal(t, fiber.StatusInternalServerError, resp.StatusCode)
334 require.Error(t, captured)
335 require.ErrorContains(t, captured, "cache: failed to delete expired key")
336}
337
338type contextKey string
339

Callers

nothing calls this directly

Calls 10

MarshalMsgMethod · 0.95
newFailingCacheStorageFunction · 0.85
TestMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
SendStringMethod · 0.65
StatusMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected