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

Function TestSharedState_StorageErrorsArePropagated

shared_state_test.go:304–366  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestSharedState_StorageErrorsArePropagated(t *testing.T) {
305 t.Parallel()
306
307 expectedErr := errors.New("storage failed")
308 closeErr := errors.New("close failed")
309 app := New(Config{
310 SharedStorage: &errorStorage{err: expectedErr, closeErr: closeErr},
311 MsgPackEncoder: func(any) ([]byte, error) {
312 return []byte("msgpack"), nil
313 },
314 MsgPackDecoder: func([]byte, any) error {
315 return nil
316 },
317 CBOREncoder: func(any) ([]byte, error) {
318 return []byte("cbor"), nil
319 },
320 CBORDecoder: func([]byte, any) error {
321 return nil
322 },
323 XMLEncoder: func(any) ([]byte, error) {
324 return []byte("<xml/>"), nil
325 },
326 XMLDecoder: func([]byte, any) error {
327 return nil
328 },
329 })
330
331 err := app.SharedState().SetJSON("k", Map{"v": 1}, time.Second)
332 require.ErrorIs(t, err, expectedErr)
333 err = app.SharedState().SetMsgPack("k", Map{"v": 1}, time.Second)
334 require.ErrorIs(t, err, expectedErr)
335 err = app.SharedState().SetCBOR("k", Map{"v": 1}, time.Second)
336 require.ErrorIs(t, err, expectedErr)
337 err = app.SharedState().SetXML("k", Map{"v": 1}, time.Second)
338 require.ErrorIs(t, err, expectedErr)
339
340 err = app.SharedState().Set("k", []byte("v"), time.Second)
341 require.ErrorIs(t, err, expectedErr)
342
343 _, _, err = app.SharedState().Get("k")
344 require.ErrorIs(t, err, expectedErr)
345
346 _, _, err = app.SharedState().GetJSON("k", &Map{})
347 require.ErrorIs(t, err, expectedErr)
348 _, _, err = app.SharedState().GetMsgPack("k", &Map{})
349 require.ErrorIs(t, err, expectedErr)
350 _, _, err = app.SharedState().GetCBOR("k", &Map{})
351 require.ErrorIs(t, err, expectedErr)
352 _, _, err = app.SharedState().GetXML("k", &Map{})
353 require.ErrorIs(t, err, expectedErr)
354
355 _, err = app.SharedState().Has("k")
356 require.ErrorIs(t, err, expectedErr)
357
358 err = app.SharedState().Delete("k")
359 require.ErrorIs(t, err, expectedErr)
360
361 err = app.SharedState().Reset()

Callers

nothing calls this directly

Calls 15

SharedStateMethod · 0.80
SetMsgPackMethod · 0.80
GetJSONMethod · 0.80
GetMsgPackMethod · 0.80
GetCBORMethod · 0.80
GetXMLMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
DeleteMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected