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

Function TestSharedState_ContextAwareVariants

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

Source from the content-addressed store, hash-verified

220}
221
222func TestSharedState_ContextAwareVariants(t *testing.T) {
223 t.Parallel()
224
225 type testContextKey string
226
227 ctxKey := testContextKey("tenant")
228 store := &contextCheckingStorage{ctxKey: ctxKey, base: newSharedStateMemoryStorage(t)}
229 app := New(Config{SharedStorage: store})
230
231 t.Run("missing context", func(t *testing.T) {
232 t.Parallel()
233
234 err := app.SharedState().SetJSONWithContext(context.Background(), "key", Map{"ok": true}, time.Second)
235 require.Error(t, err)
236 })
237
238 t.Run("context propagation", func(t *testing.T) {
239 t.Parallel()
240
241 ctx := context.WithValue(context.Background(), ctxKey, "value")
242 err := app.SharedState().SetJSONWithContext(ctx, "key", Map{"ok": true}, time.Second)
243 require.NoError(t, err)
244
245 var out map[string]bool
246 _, found, err := app.SharedState().GetJSONWithContext(ctx, "key", &out)
247 require.NoError(t, err)
248 require.True(t, found)
249 require.True(t, out["ok"])
250
251 has, err := app.SharedState().HasWithContext(ctx, "key")
252 require.NoError(t, err)
253 require.True(t, has)
254
255 err = app.SharedState().DeleteWithContext(ctx, "key")
256 require.NoError(t, err)
257 })
258}
259
260func TestSharedState_KeyNamespacing(t *testing.T) {
261 t.Parallel()

Callers

nothing calls this directly

Calls 9

SetJSONWithContextMethod · 0.80
SharedStateMethod · 0.80
GetJSONWithContextMethod · 0.80
HasWithContextMethod · 0.80
testContextKeyTypeAlias · 0.70
NewFunction · 0.70
ErrorMethod · 0.65
DeleteWithContextMethod · 0.65

Tested by

no test coverage detected