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

Function TestSharedState_KeyNamespacing

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

Source from the content-addressed store, hash-verified

258}
259
260func TestSharedState_KeyNamespacing(t *testing.T) {
261 t.Parallel()
262
263 store := newSharedStateMemoryStorage(t)
264 appOne := New(Config{AppName: "app-one", SharedStorage: store})
265 appTwo := New(Config{AppName: "app-two", SharedStorage: store})
266
267 err := appOne.SharedState().SetJSON("same-key", Map{"app": 1}, time.Minute)
268 require.NoError(t, err)
269 err = appTwo.SharedState().SetJSON("same-key", Map{"app": 2}, time.Minute)
270 require.NoError(t, err)
271
272 var outOne map[string]int
273 _, found, err := appOne.SharedState().GetJSON("same-key", &outOne)
274 require.NoError(t, err)
275 require.True(t, found)
276 require.Equal(t, 1, outOne["app"])
277
278 var outTwo map[string]int
279 _, found, err = appTwo.SharedState().GetJSON("same-key", &outTwo)
280 require.NoError(t, err)
281 require.True(t, found)
282 require.Equal(t, 2, outTwo["app"])
283}
284
285func TestSharedState_KeyNamespacingWithOverlappingPrefixes(t *testing.T) {
286 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