(t *testing.T)
| 21 | } |
| 22 | |
| 23 | func TestWriteTool_CreateNewFile(t *testing.T) { |
| 24 | tool, err := NewWriteTool(nil) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Failed to create Write tool: %v", err) |
| 27 | } |
| 28 | |
| 29 | helper := NewTestHelper(t) |
| 30 | defer helper.CleanupAll() |
| 31 | |
| 32 | filePath := helper.TmpDir + "/new_file.txt" |
| 33 | content := "This is new content" |
| 34 | |
| 35 | input := map[string]any{ |
| 36 | "file_path": filePath, |
| 37 | "content": content, |
| 38 | } |
| 39 | |
| 40 | result := ExecuteToolWithRealFS(t, tool, input) |
| 41 | result = AssertToolSuccess(t, result) |
| 42 | |
| 43 | // 验证文件被创建 |
| 44 | AssertFileExists(t, filePath) |
| 45 | AssertFileContent(t, filePath, content) |
| 46 | |
| 47 | // 验证响应字段 |
| 48 | if result["file_path"] != filePath { |
| 49 | t.Error("file_path should be echoed back") |
| 50 | } |
| 51 | |
| 52 | if fileSize, exists := result["file_size"]; !exists { |
| 53 | t.Error("Result should contain 'file_size' field") |
| 54 | } else if fileSizeInt, ok := fileSize.(int); !ok || fileSizeInt != len(content) { |
| 55 | t.Errorf("file_size should be %d, got %v", len(content), fileSize) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestWriteTool_OverwriteExisting(t *testing.T) { |
| 60 | tool, err := NewWriteTool(nil) |
nothing calls this directly
no test coverage detected