Skip to content

Commit

Permalink
test: real, direct match
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Nov 6, 2020
1 parent 2364766 commit 3ae9006
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 2 additions & 7 deletions glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,14 @@ func GlobWithFs(fs afero.Fs, pattern string) ([]string, error) {
func filesInDirectory(fs afero.Fs, dir string) ([]string, error) {
var files []string

err := afero.Walk(fs, dir, func(currentPath string, info os.FileInfo, err error) error {
return files, afero.Walk(fs, dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

files = append(files, currentPath)

files = append(files, path)
return nil
})

return files, err
}
18 changes: 18 additions & 0 deletions glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import (
)

func TestGlob(t *testing.T) {
t.Run("real", func(t *testing.T) {
matches, err := Glob("*_test.go")
require.NoError(t, err)
require.Equal(t, []string{
"glob_test.go",
"prefix_test.go",
}, matches)
})

t.Run("simple", func(t *testing.T) {
matches, err := globInMemoryFs("./a/*/*", []string{
"./c/file1.txt",
Expand Down Expand Up @@ -51,6 +60,15 @@ func TestGlob(t *testing.T) {
}, matches)
})

t.Run("direct match", func(t *testing.T) {
matches, err := globInMemoryFs("a/b/c", []string{
"./a/nope.txt",
"./a/b/c",
})
require.NoError(t, err)
require.Equal(t, []string{"a/b/c"}, matches)
})

t.Run("no matches", func(t *testing.T) {
matches, err := globInMemoryFs("z/*", []string{
"./a/nope.txt",
Expand Down

0 comments on commit 3ae9006

Please sign in to comment.