(t *testing.T)
| 429 | } |
| 430 | |
| 431 | func TestCachedTool_DifferentInputs(t *testing.T) { |
| 432 | config := &CacheConfig{ |
| 433 | Enabled: true, |
| 434 | Strategy: CacheStrategyMemory, |
| 435 | TTL: 1 * time.Hour, |
| 436 | } |
| 437 | |
| 438 | cache := NewToolCache(config) |
| 439 | |
| 440 | mockTool := &MockTool{ |
| 441 | name: "test_tool", |
| 442 | description: "Test tool", |
| 443 | } |
| 444 | |
| 445 | cachedTool := NewCachedTool(mockTool, cache) |
| 446 | |
| 447 | ctx := context.Background() |
| 448 | |
| 449 | // 不同的输入应该执行不同的调用 |
| 450 | input1 := map[string]any{"test": "value1"} |
| 451 | input2 := map[string]any{"test": "value2"} |
| 452 | |
| 453 | _, err := cachedTool.Execute(ctx, input1, nil) |
| 454 | if err != nil { |
| 455 | t.Fatalf("Failed to execute: %v", err) |
| 456 | } |
| 457 | |
| 458 | _, err = cachedTool.Execute(ctx, input2, nil) |
| 459 | if err != nil { |
| 460 | t.Fatalf("Failed to execute: %v", err) |
| 461 | } |
| 462 | |
| 463 | if mockTool.callCount != 2 { |
| 464 | t.Errorf("Expected 2 calls for different inputs, got: %d", mockTool.callCount) |
| 465 | } |
| 466 | |
| 467 | // 相同输入应该使用缓存 |
| 468 | _, err = cachedTool.Execute(ctx, input1, nil) |
| 469 | if err != nil { |
| 470 | t.Fatalf("Failed to execute: %v", err) |
| 471 | } |
| 472 | |
| 473 | if mockTool.callCount != 2 { |
| 474 | t.Errorf("Expected 2 calls (third was cached), got: %d", mockTool.callCount) |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | func TestToolCache_Disabled(t *testing.T) { |
| 479 | config := &CacheConfig{ |
nothing calls this directly
no test coverage detected