1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 16:45:07 +00:00

fix(analyze): count top-level files in json output

This commit is contained in:
tw93
2026-03-07 10:10:41 +08:00
parent 09d0de0c8e
commit 89a9ae0ce2
2 changed files with 28 additions and 1 deletions

View File

@@ -91,6 +91,31 @@ func TestScanPathConcurrentBasic(t *testing.T) {
}
}
func TestPerformScanForJSONCountsTopLevelFiles(t *testing.T) {
root := t.TempDir()
rootFile := filepath.Join(root, "root.txt")
if err := os.WriteFile(rootFile, []byte("root-data"), 0o644); err != nil {
t.Fatalf("write root file: %v", err)
}
nested := filepath.Join(root, "nested")
if err := os.MkdirAll(nested, 0o755); err != nil {
t.Fatalf("create nested dir: %v", err)
}
nestedFile := filepath.Join(nested, "nested.txt")
if err := os.WriteFile(nestedFile, []byte("nested-data"), 0o644); err != nil {
t.Fatalf("write nested file: %v", err)
}
result := performScanForJSON(root)
if result.TotalFiles != 2 {
t.Fatalf("expected 2 files in JSON output, got %d", result.TotalFiles)
}
}
func TestDeletePathWithProgress(t *testing.T) {
skipIfFinderUnavailable(t)

View File

@@ -58,6 +58,8 @@ func performScanForJSON(path string) jsonOutput {
info, err := item.Info()
if err == nil {
size = info.Size()
atomic.AddInt64(&filesScanned, 1)
atomic.AddInt64(&bytesScanned, size)
}
}
@@ -74,6 +76,6 @@ func performScanForJSON(path string) jsonOutput {
Path: path,
Entries: entries,
TotalSize: totalSize,
TotalFiles: filesScanned,
TotalFiles: atomic.LoadInt64(&filesScanned),
}
}