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

Function TestCachedTool_DifferentInputs

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

Source from the content-addressed store, hash-verified

429}
430
431func 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
478func TestToolCache_Disabled(t *testing.T) {
479 config := &CacheConfig{

Callers

nothing calls this directly

Calls 3

ExecuteMethod · 0.95
NewToolCacheFunction · 0.85
NewCachedToolFunction · 0.85

Tested by

no test coverage detected