(t *testing.T)
| 305 | } |
| 306 | |
| 307 | func 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 | |
| 345 | func TestToolCache_GenerateKey(t *testing.T) { |
| 346 | cache := NewToolCache(DefaultCacheConfig()) |
nothing calls this directly
no test coverage detected