BenchmarkPathValidation 性能测试: 路径验证
(b *testing.B)
| 375 | |
| 376 | // BenchmarkPathValidation 性能测试: 路径验证 |
| 377 | func BenchmarkPathValidation(b *testing.B) { |
| 378 | backend := backends.NewStateBackend() |
| 379 | middleware := NewFilesystemMiddleware(&FilesystemMiddlewareConfig{ |
| 380 | Backend: backend, |
| 381 | EnablePathValidation: true, |
| 382 | AllowedPathPrefixes: []string{"/workspace/", "/tmp/"}, |
| 383 | }) |
| 384 | |
| 385 | paths := []string{ |
| 386 | "/workspace/file.txt", |
| 387 | "/tmp/cache.dat", |
| 388 | "workspace/nested/deep/file.go", |
| 389 | "/workspace/./redundant/../path/file.txt", |
| 390 | } |
| 391 | |
| 392 | for i := 0; b.Loop(); i++ { |
| 393 | path := paths[i%len(paths)] |
| 394 | _, _ = middleware.validatePath(path) |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // BenchmarkPathValidation_Disabled 性能测试: 禁用路径验证 |
| 399 | func BenchmarkPathValidation_Disabled(b *testing.B) { |
nothing calls this directly
no test coverage detected