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

Function TestSharedState_UsesAppCBORCodec

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

Source from the content-addressed store, hash-verified

649}
650
651func TestSharedState_UsesAppCBORCodec(t *testing.T) {
652 t.Parallel()
653
654 encoderCalled := false
655 decoderCalled := false
656
657 app := New(Config{
658 SharedStorage: newSharedStateMemoryStorage(t),
659 CBOREncoder: func(_ any) ([]byte, error) {
660 encoderCalled = true
661 return []byte("cbor-payload"), nil
662 },
663 CBORDecoder: func(data []byte, out any) error {
664 decoderCalled = true
665 ptr, ok := out.(*string)
666 if ok {
667 *ptr = string(data)
668 }
669 return nil
670 },
671 })
672
673 require.NoError(t, app.SharedState().SetCBOR("codec", Map{"ignored": true}, time.Minute))
674
675 var out string
676 raw, found, err := app.SharedState().GetCBOR("codec", &out)
677 require.NoError(t, err)
678 require.True(t, found)
679 require.Equal(t, []byte("cbor-payload"), raw)
680 require.Equal(t, "cbor-payload", out)
681 require.True(t, encoderCalled)
682 require.True(t, decoderCalled)
683}
684
685func TestSharedState_UsesAppXMLCodec(t *testing.T) {
686 t.Parallel()

Callers

nothing calls this directly

Calls 5

SharedStateMethod · 0.80
GetCBORMethod · 0.80
NewFunction · 0.70
SetCBORMethod · 0.45

Tested by

no test coverage detected