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

Function TestBackendIntegration

pkg/middleware/integration_test.go:181–235  ·  view source on GitHub ↗

TestBackendIntegration 集成测试: Backend 与 Middleware

(t *testing.T)

Source from the content-addressed store, hash-verified

179
180// TestBackendIntegration 集成测试: Backend 与 Middleware
181func TestBackendIntegration(t *testing.T) {
182 ctx := context.Background()
183
184 // 测试不同的 Backend
185 backends := map[string]backends.BackendProtocol{
186 "state": backends.NewStateBackend(),
187 }
188
189 for name, backend := range backends {
190 t.Run(name, func(t *testing.T) {
191 // 创建 Middleware
192 middleware := NewFilesystemMiddleware(&FilesystemMiddlewareConfig{
193 Backend: backend,
194 })
195
196 // 写入测试数据
197 _, err := backend.Write(ctx, "/test.txt", "line1\nline2\nline3")
198 if err != nil {
199 t.Fatalf("Write failed: %v", err)
200 }
201
202 // 读取数据
203 content, err := backend.Read(ctx, "/test.txt", 0, 0)
204 if err != nil {
205 t.Fatalf("Read failed: %v", err)
206 }
207
208 if !strings.Contains(content, "line1") {
209 t.Errorf("Content should contain 'line1', got: %s", content)
210 }
211
212 // 测试编辑
213 result, err := backend.Edit(ctx, "/test.txt", "line1", "LINE1", false)
214 if err != nil {
215 t.Fatalf("Edit failed: %v", err)
216 }
217
218 if result.ReplacementsMade != 1 {
219 t.Errorf("Expected 1 replacement, got %d", result.ReplacementsMade)
220 }
221
222 // 验证编辑结果
223 newContent, _ := backend.Read(ctx, "/test.txt", 0, 0)
224 if !strings.Contains(newContent, "LINE1") {
225 t.Errorf("Content should contain 'LINE1' after edit, got: %s", newContent)
226 }
227
228 // 测试 Middleware 工具
229 tools := middleware.Tools()
230 if len(tools) != 6 {
231 t.Errorf("Expected 6 tools, got %d", len(tools))
232 }
233 })
234 }
235}
236
237// BenchmarkMiddlewareStack 性能测试: Middleware Stack
238func BenchmarkMiddlewareStack(b *testing.B) {

Callers

nothing calls this directly

Calls 6

ToolsMethod · 0.95
NewFilesystemMiddlewareFunction · 0.85
WriteMethod · 0.65
ReadMethod · 0.65
EditMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected