mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 18:30:08 +00:00
fix(analyze): count top-level files in json output
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user