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

Function TestWriteTool_CreateNewFile

pkg/tools/builtin/write_test.go:23–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func 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
59func TestWriteTool_OverwriteExisting(t *testing.T) {
60 tool, err := NewWriteTool(nil)

Callers

nothing calls this directly

Calls 8

CleanupAllMethod · 0.95
NewWriteToolFunction · 0.85
NewTestHelperFunction · 0.85
ExecuteToolWithRealFSFunction · 0.85
AssertToolSuccessFunction · 0.85
AssertFileExistsFunction · 0.85
AssertFileContentFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected