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

Function TestToolCache_GenerateKey

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

Source from the content-addressed store, hash-verified

343}
344
345func TestToolCache_GenerateKey(t *testing.T) {
346 cache := NewToolCache(DefaultCacheConfig())
347
348 // 相同输入应该生成相同的键
349 input1 := map[string]any{"a": 1, "b": "test"}
350 input2 := map[string]any{"a": 1, "b": "test"}
351
352 key1 := cache.GenerateKey("tool1", input1)
353 key2 := cache.GenerateKey("tool1", input2)
354
355 if key1 != key2 {
356 t.Errorf("Expected same key for same input, got: %s != %s", key1, key2)
357 }
358
359 // 不同输入应该生成不同的键
360 input3 := map[string]any{"a": 2, "b": "test"}
361 key3 := cache.GenerateKey("tool1", input3)
362
363 if key1 == key3 {
364 t.Error("Expected different key for different input")
365 }
366
367 // 不同工具名应该生成不同的键
368 key4 := cache.GenerateKey("tool2", input1)
369
370 if key1 == key4 {
371 t.Error("Expected different key for different tool name")
372 }
373}
374
375func TestCachedTool_Execute(t *testing.T) {
376 config := &CacheConfig{

Callers

nothing calls this directly

Calls 4

GenerateKeyMethod · 0.95
NewToolCacheFunction · 0.85
DefaultCacheConfigFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected