MCPcopy Create free account
hub / github.com/astercloud/aster / TestToolCache_Clear

Function TestToolCache_Clear

pkg/tools/cache_test.go:307–343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

305}
306
307func TestToolCache_Clear(t *testing.T) {
308 config := &CacheConfig{
309 Enabled: true,
310 Strategy: CacheStrategyMemory,
311 TTL: 1 * time.Hour,
312 }
313
314 cache := NewToolCache(config)
315 ctx := context.Background()
316
317 // 添加多个条目
318 for i := range 5 {
319 key := cache.GenerateKey("tool", map[string]any{"index": i})
320 err := cache.Set(ctx, key, i, config.TTL)
321 if err != nil {
322 t.Fatalf("Failed to set cache: %v", err)
323 }
324 }
325
326 // 验证统计
327 stats := cache.GetStats()
328 if stats.ItemCount != 5 {
329 t.Errorf("Expected 5 items, got: %d", stats.ItemCount)
330 }
331
332 // 清空
333 err := cache.Clear()
334 if err != nil {
335 t.Fatalf("Failed to clear cache: %v", err)
336 }
337
338 // 验证已清空
339 stats = cache.GetStats()
340 if stats.ItemCount != 0 {
341 t.Errorf("Expected 0 items after clear, got: %d", stats.ItemCount)
342 }
343}
344
345func TestToolCache_GenerateKey(t *testing.T) {
346 cache := NewToolCache(DefaultCacheConfig())

Callers

nothing calls this directly

Calls 5

GenerateKeyMethod · 0.95
SetMethod · 0.95
GetStatsMethod · 0.95
ClearMethod · 0.95
NewToolCacheFunction · 0.85

Tested by

no test coverage detected