(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestReadDirCallback(t *testing.T) { |
| 18 | // Create a temporary test directory |
| 19 | tmpDir, err := os.MkdirTemp("", "readdir_test") |
| 20 | if err != nil { |
| 21 | t.Fatalf("Failed to create temp dir: %v", err) |
| 22 | } |
| 23 | defer os.RemoveAll(tmpDir) |
| 24 | |
| 25 | // Create test files and directories |
| 26 | testFile1 := filepath.Join(tmpDir, "file1.txt") |
| 27 | testFile2 := filepath.Join(tmpDir, "file2.log") |
| 28 | testSubDir := filepath.Join(tmpDir, "subdir") |
| 29 | |
| 30 | if err := os.WriteFile(testFile1, []byte("test content 1"), 0644); err != nil { |
| 31 | t.Fatalf("Failed to create test file 1: %v", err) |
| 32 | } |
| 33 | if err := os.WriteFile(testFile2, []byte("test content 2"), 0644); err != nil { |
| 34 | t.Fatalf("Failed to create test file 2: %v", err) |
| 35 | } |
| 36 | if err := os.Mkdir(testSubDir, 0755); err != nil { |
| 37 | t.Fatalf("Failed to create test subdir: %v", err) |
| 38 | } |
| 39 | |
| 40 | // Test reading the directory |
| 41 | input := map[string]any{ |
| 42 | "path": tmpDir, |
| 43 | } |
| 44 | |
| 45 | result, err := readDirCallback(input, &uctypes.UIMessageDataToolUse{}) |
| 46 | if err != nil { |
| 47 | t.Fatalf("readDirCallback failed: %v", err) |
| 48 | } |
| 49 | |
| 50 | resultMap, ok := result.(map[string]any) |
| 51 | if !ok { |
| 52 | t.Fatalf("Result is not a map") |
| 53 | } |
| 54 | |
| 55 | // Verify the result contains expected fields |
| 56 | if resultMap["path"] != tmpDir { |
| 57 | t.Errorf("Expected path %q, got %q", tmpDir, resultMap["path"]) |
| 58 | } |
| 59 | |
| 60 | entryCount, ok := resultMap["entry_count"].(int) |
| 61 | if !ok { |
| 62 | t.Fatalf("entry_count is not an int") |
| 63 | } |
| 64 | if entryCount != 3 { |
| 65 | t.Errorf("Expected 3 entries, got %d", entryCount) |
| 66 | } |
| 67 | |
| 68 | entries, ok := resultMap["entries"].([]fileutil.DirEntryOut) |
| 69 | if !ok { |
| 70 | t.Fatalf("entries is not a slice of DirEntryOut") |
| 71 | } |
| 72 | |
| 73 | // Check that we have the expected entries |
| 74 | foundFiles := 0 |
nothing calls this directly
no test coverage detected