Skip to content

Commit

Permalink
Feature: Add support for finding empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
nick spragg committed Apr 12, 2017
1 parent 32dde23 commit 8dd5dac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions filehound/filehound.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func (f *Filehound) Size(size int64) *Filehound {
})
}

// IsEmpty ...
func (f *Filehound) IsEmpty() *Filehound {
return f.Size(0)
}

// Discard ...
func (f *Filehound) Discard(pattern string) *Filehound {
return f.Filter(func(path string, info os.FileInfo) bool {
return false
})
}

func (f *Filehound) isMatch(path string, info os.FileInfo) bool {
if len(f.filters) == 0 {
return true
Expand Down
12 changes: 12 additions & 0 deletions filehound/filehound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestSearchAtDepthN(t *testing.T) {
Path(deeplyNestedPath).
Depth(3).
Find()

expected := qualifyNames(
"./fixtures/deeplyNested/c.json",
"./fixtures/deeplyNested/d.json",
Expand All @@ -158,3 +159,14 @@ func TestSearchAtDepthN(t *testing.T) {

assertFiles(t, actual, expected)
}

func TestSearchByEmptyFile(t *testing.T) {
actual := filehound.Create().
Path(justFilesPath).
IsEmpty().
Find()

expected := qualifyNames("./fixtures/justFiles/a.json", "./fixtures/justFiles/dummy.txt")

assertFiles(t, actual, expected)
}

0 comments on commit 8dd5dac

Please sign in to comment.