(t *testing.T)
| 220 | } |
| 221 | |
| 222 | func 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 | |
| 260 | func TestSharedState_KeyNamespacing(t *testing.T) { |
| 261 | t.Parallel() |
nothing calls this directly
no test coverage detected