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

Function TestSharedState_UsesAppMsgPackCodec

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

Source from the content-addressed store, hash-verified

590}
591
592func TestSharedState_UsesAppMsgPackCodec(t *testing.T) {
593 t.Parallel()
594
595 encoderCalled := false
596 decoderCalled := false
597
598 app := New(Config{
599 SharedStorage: newSharedStateMemoryStorage(t),
600 MsgPackEncoder: func(_ any) ([]byte, error) {
601 encoderCalled = true
602 return []byte("msgpack-payload"), nil
603 },
604 MsgPackDecoder: func(data []byte, out any) error {
605 decoderCalled = true
606 ptr, ok := out.(*string)
607 if ok {
608 *ptr = string(data)
609 }
610 return nil
611 },
612 })
613
614 require.NoError(t, app.SharedState().SetMsgPack("codec", Map{"ignored": true}, time.Minute))
615
616 var out string
617 raw, found, err := app.SharedState().GetMsgPack("codec", &out)
618 require.NoError(t, err)
619 require.True(t, found)
620 require.Equal(t, []byte("msgpack-payload"), raw)
621 require.Equal(t, "msgpack-payload", out)
622 require.True(t, encoderCalled)
623 require.True(t, decoderCalled)
624}
625
626func TestSharedState_UnconfiguredCodecsReturnErrorInsteadOfPanic(t *testing.T) {
627 t.Parallel()

Callers

nothing calls this directly

Calls 5

SetMsgPackMethod · 0.80
SharedStateMethod · 0.80
GetMsgPackMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected