Merge pull request #127 from setekhid/master

make IsDotFile do not treat '.' as true
This commit is contained in:
Alfredo Beaumont 2017-10-18 12:49:43 +02:00 committed by GitHub
commit 91c074ea1d
2 changed files with 19 additions and 1 deletions

View File

@ -40,7 +40,9 @@ func IsConfiguration(path string) bool {
// IsDotFile returns whether or not path has dot as a prefix. // IsDotFile returns whether or not path has dot as a prefix.
func IsDotFile(path string) bool { func IsDotFile(path string) bool {
return strings.HasPrefix(filepath.Base(path), ".") path = filepath.Clean(path)
base := filepath.Base(path)
return strings.HasPrefix(base, ".") && base != "." && base != ".."
} }
// IsVendor returns whether or not path is a vendor path. // IsVendor returns whether or not path is a vendor path.

View File

@ -82,6 +82,22 @@ func (s *EnryTestSuite) TestIsBinary() {
} }
} }
func (s *EnryTestSuite) TestIsDotFile() {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsDotFile_1", path: "foo/bar/./", expected: false},
{name: "TestIsDotFile_2", path: "./", expected: false},
}
for _, test := range tests {
is := IsDotFile(test.path)
assert.Equal(s.T(), test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestFileCountListSort(t *testing.T) { func TestFileCountListSort(t *testing.T) {
sampleData := FileCountList{{"a", 8}, {"b", 65}, {"c", 20}, {"d", 90}} sampleData := FileCountList{{"a", 8}, {"b", 65}, {"c", 20}, {"d", 90}}
const ascending = "ASC" const ascending = "ASC"