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

Function TestSharedState_UsesAppJSONCodec

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

Source from the content-addressed store, hash-verified

561}
562
563func TestSharedState_UsesAppJSONCodec(t *testing.T) {
564 t.Parallel()
565
566 encoderCalled := false
567 decoderCalled := false
568
569 app := New(Config{
570 SharedStorage: newSharedStateMemoryStorage(t),
571 JSONEncoder: func(_ any) ([]byte, error) {
572 encoderCalled = true
573 return json.Marshal(Map{"via": "custom-encoder"})
574 },
575 JSONDecoder: func(data []byte, out any) error {
576 decoderCalled = true
577 return json.Unmarshal(data, out)
578 },
579 })
580
581 require.NoError(t, app.SharedState().SetJSON("codec", Map{"ignored": true}, time.Minute))
582
583 var out map[string]string
584 _, found, err := app.SharedState().GetJSON("codec", &out)
585 require.NoError(t, err)
586 require.True(t, found)
587 require.Equal(t, "custom-encoder", out["via"])
588 require.True(t, encoderCalled)
589 require.True(t, decoderCalled)
590}
591
592func TestSharedState_UsesAppMsgPackCodec(t *testing.T) {
593 t.Parallel()

Callers

nothing calls this directly

Calls 5

SharedStateMethod · 0.80
GetJSONMethod · 0.80
NewFunction · 0.70
SetJSONMethod · 0.45

Tested by

no test coverage detected