TestDefaultCompressionService_Cache 测试缓存功能
(t *testing.T)
| 87 | |
| 88 | // TestDefaultCompressionService_Cache 测试缓存功能 |
| 89 | func TestDefaultCompressionService_Cache(t *testing.T) { |
| 90 | svc := NewDefaultCompressionService(nil, 100) |
| 91 | prompt := generateTestPrompt() |
| 92 | |
| 93 | opts := &CompressOptions{ |
| 94 | Mode: ModeSimple, |
| 95 | Level: LevelModerate, |
| 96 | UseCache: true, |
| 97 | } |
| 98 | |
| 99 | // 第一次压缩 |
| 100 | result1, err := svc.CompressSystemPrompt(context.Background(), prompt, opts) |
| 101 | if err != nil { |
| 102 | t.Fatalf("First compress failed: %v", err) |
| 103 | } |
| 104 | if result1.CacheHit { |
| 105 | t.Error("First compress should not be cache hit") |
| 106 | } |
| 107 | |
| 108 | // 第二次压缩(应该命中缓存) |
| 109 | result2, err := svc.CompressSystemPrompt(context.Background(), prompt, opts) |
| 110 | if err != nil { |
| 111 | t.Fatalf("Second compress failed: %v", err) |
| 112 | } |
| 113 | if !result2.CacheHit { |
| 114 | t.Error("Second compress should be cache hit") |
| 115 | } |
| 116 | |
| 117 | // 验证结果相同 |
| 118 | if result1.Compressed != result2.Compressed { |
| 119 | t.Error("Cache hit should return same result") |
| 120 | } |
| 121 | |
| 122 | // 验证统计 |
| 123 | stats := svc.GetStats() |
| 124 | if stats.CacheHits != 1 { |
| 125 | t.Errorf("Expected 1 cache hit, got %d", stats.CacheHits) |
| 126 | } |
| 127 | if stats.CacheMisses != 1 { |
| 128 | t.Errorf("Expected 1 cache miss, got %d", stats.CacheMisses) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // TestDefaultCompressionService_Stats 测试统计功能 |
| 133 | func TestDefaultCompressionService_Stats(t *testing.T) { |
nothing calls this directly
no test coverage detected