Skip to content

Commit

Permalink
fix old test, after adding more test files
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 7, 2023
1 parent 345162d commit c3afb8e
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 75 deletions.
23 changes: 13 additions & 10 deletions paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,34 +306,37 @@ func TestFilterDirs(t *testing.T) {

list, err := testPath.ReadDir()
require.NoError(t, err)
require.Len(t, list, 6)
require.Len(t, list, 7)

pathEqualsTo(t, "_testdata/anotherFile", list[0])
pathEqualsTo(t, "_testdata/file", list[1])
pathEqualsTo(t, "_testdata/folder", list[2])
pathEqualsTo(t, "_testdata/symlinktofolder", list[3])
pathEqualsTo(t, "_testdata/test.txt", list[4])
pathEqualsTo(t, "_testdata/test.txt.gz", list[5])
pathEqualsTo(t, "_testdata/folder_containing_symlinks", list[3])
pathEqualsTo(t, "_testdata/symlinktofolder", list[4])
pathEqualsTo(t, "_testdata/test.txt", list[5])
pathEqualsTo(t, "_testdata/test.txt.gz", list[6])

list.FilterDirs()
require.Len(t, list, 2)
require.Len(t, list, 3)
pathEqualsTo(t, "_testdata/folder", list[0])
pathEqualsTo(t, "_testdata/symlinktofolder", list[1])
pathEqualsTo(t, "_testdata/folder_containing_symlinks", list[1])
pathEqualsTo(t, "_testdata/symlinktofolder", list[2])
}

func TestFilterOutDirs(t *testing.T) {
testPath := New("_testdata")

list, err := testPath.ReadDir()
require.NoError(t, err)
require.Len(t, list, 6)
require.Len(t, list, 7)

pathEqualsTo(t, "_testdata/anotherFile", list[0])
pathEqualsTo(t, "_testdata/file", list[1])
pathEqualsTo(t, "_testdata/folder", list[2])
pathEqualsTo(t, "_testdata/symlinktofolder", list[3])
pathEqualsTo(t, "_testdata/test.txt", list[4])
pathEqualsTo(t, "_testdata/test.txt.gz", list[5])
pathEqualsTo(t, "_testdata/folder_containing_symlinks", list[3])
pathEqualsTo(t, "_testdata/symlinktofolder", list[4])
pathEqualsTo(t, "_testdata/test.txt", list[5])
pathEqualsTo(t, "_testdata/test.txt.gz", list[6])

list.FilterOutDirs()
require.Len(t, list, 4)
Expand Down
185 changes: 120 additions & 65 deletions readdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestReadDirRecursive(t *testing.T) {

list, err := testPath.ReadDirRecursive()
require.NoError(t, err)
require.Len(t, list, 16)
require.Len(t, list, 25)

pathEqualsTo(t, "_testdata/anotherFile", list[0])
pathEqualsTo(t, "_testdata/file", list[1])
Expand All @@ -52,14 +52,25 @@ func TestReadDirRecursive(t *testing.T) {
pathEqualsTo(t, "_testdata/folder/file3", list[5])
pathEqualsTo(t, "_testdata/folder/subfolder", list[6])
pathEqualsTo(t, "_testdata/folder/subfolder/file4", list[7])
pathEqualsTo(t, "_testdata/symlinktofolder", list[8])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", list[9])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", list[10])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", list[11])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", list[12])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", list[13])
pathEqualsTo(t, "_testdata/test.txt", list[14])
pathEqualsTo(t, "_testdata/test.txt.gz", list[15])

pathEqualsTo(t, "_testdata/folder_containing_symlinks", list[8])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file", list[9])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file2", list[10])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", list[11])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", list[12])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file2", list[13])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file3", list[14])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder", list[15])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder/file4", list[16])

pathEqualsTo(t, "_testdata/symlinktofolder", list[17])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", list[18])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", list[19])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", list[20])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", list[21])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", list[22])
pathEqualsTo(t, "_testdata/test.txt", list[23])
pathEqualsTo(t, "_testdata/test.txt.gz", list[24])
}

func TestReadDirRecursiveSymLinkLoop(t *testing.T) {
Expand Down Expand Up @@ -110,7 +121,7 @@ func TestReadDirRecursiveFiltered(t *testing.T) {
l, err := testdata.ReadDirRecursiveFiltered(nil)
require.NoError(t, err)
l.Sort()
require.Len(t, l, 16)
require.Len(t, l, 25)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder", l[2])
Expand All @@ -119,42 +130,62 @@ func TestReadDirRecursiveFiltered(t *testing.T) {
pathEqualsTo(t, "_testdata/folder/file3", l[5])
pathEqualsTo(t, "_testdata/folder/subfolder", l[6])
pathEqualsTo(t, "_testdata/folder/subfolder/file4", l[7])
pathEqualsTo(t, "_testdata/symlinktofolder", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[9])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[10])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[11])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[12])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[13])
pathEqualsTo(t, "_testdata/test.txt", l[14])
pathEqualsTo(t, "_testdata/test.txt.gz", l[15])

pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[8])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file", l[9])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file2", l[10])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", l[11])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", l[12])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file2", l[13])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file3", l[14])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder", l[15])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder/file4", l[16])

pathEqualsTo(t, "_testdata/symlinktofolder", l[17])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[18])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[19])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[20])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[21])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[22])
pathEqualsTo(t, "_testdata/test.txt", l[23])
pathEqualsTo(t, "_testdata/test.txt.gz", l[24])

l, err = testdata.ReadDirRecursiveFiltered(FilterOutDirectories())
require.NoError(t, err)
l.Sort()
require.Len(t, l, 6)
require.Len(t, l, 7)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder", l[2]) // <- this is listed but not traversed
pathEqualsTo(t, "_testdata/symlinktofolder", l[3]) // <- this is listed but not traversed
pathEqualsTo(t, "_testdata/test.txt", l[4])
pathEqualsTo(t, "_testdata/test.txt.gz", l[5])
pathEqualsTo(t, "_testdata/folder", l[2]) // <- this is listed but not traversed
pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[3]) // <- this is listed but not traversed
pathEqualsTo(t, "_testdata/symlinktofolder", l[4]) // <- this is listed but not traversed
pathEqualsTo(t, "_testdata/test.txt", l[5])
pathEqualsTo(t, "_testdata/test.txt.gz", l[6])

l, err = testdata.ReadDirRecursiveFiltered(nil, FilterOutDirectories())
require.NoError(t, err)
l.Sort()
require.Len(t, l, 12)
require.Len(t, l, 18)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder/.hidden", l[2])
pathEqualsTo(t, "_testdata/folder/file2", l[3])
pathEqualsTo(t, "_testdata/folder/file3", l[4])
pathEqualsTo(t, "_testdata/folder/subfolder/file4", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[6])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[7])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[9])
pathEqualsTo(t, "_testdata/test.txt", l[10])
pathEqualsTo(t, "_testdata/test.txt.gz", l[11])

pathEqualsTo(t, "_testdata/folder_containing_symlinks/file", l[6])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file2", l[7])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", l[8])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file2", l[9])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file3", l[10])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder/file4", l[11])

pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[12])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[13])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[14])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[15])
pathEqualsTo(t, "_testdata/test.txt", l[16])
pathEqualsTo(t, "_testdata/test.txt.gz", l[17])

l, err = testdata.ReadDirRecursiveFiltered(FilterOutDirectories(), FilterOutDirectories())
require.NoError(t, err)
Expand All @@ -168,80 +199,104 @@ func TestReadDirRecursiveFiltered(t *testing.T) {
l, err = testdata.ReadDirRecursiveFiltered(FilterOutPrefixes("sub"), FilterOutSuffixes("3"))
require.NoError(t, err)
l.Sort()
require.Len(t, l, 12)
require.Len(t, l, 19)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder", l[2])
pathEqualsTo(t, "_testdata/folder/.hidden", l[3])
pathEqualsTo(t, "_testdata/folder/file2", l[4])
pathEqualsTo(t, "_testdata/folder/subfolder", l[5]) // <- subfolder skipped by Prefix("sub")
pathEqualsTo(t, "_testdata/symlinktofolder", l[6])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[7])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[9]) // <- subfolder skipped by Prefix("sub")
pathEqualsTo(t, "_testdata/test.txt", l[10])
pathEqualsTo(t, "_testdata/test.txt.gz", l[11])

pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[6])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file", l[7])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/file2", l[8])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", l[9])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", l[10])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/file2", l[11])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder", l[12]) // <- subfolder skipped by Prefix("sub")

pathEqualsTo(t, "_testdata/symlinktofolder", l[13])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[14])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[15])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[16]) // <- subfolder skipped by Prefix("sub")
pathEqualsTo(t, "_testdata/test.txt", l[17])
pathEqualsTo(t, "_testdata/test.txt.gz", l[18])

l, err = testdata.ReadDirRecursiveFiltered(FilterOutPrefixes("sub"), AndFilter(FilterOutSuffixes("3"), FilterOutPrefixes("fil")))
require.NoError(t, err)
l.Sort()
require.Len(t, l, 9)
require.Len(t, l, 13)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/folder", l[1])
pathEqualsTo(t, "_testdata/folder/.hidden", l[2])
pathEqualsTo(t, "_testdata/folder/subfolder", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[6])
pathEqualsTo(t, "_testdata/test.txt", l[7])
pathEqualsTo(t, "_testdata/test.txt.gz", l[8])

pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[4])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", l[5])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", l[6])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder", l[7])

pathEqualsTo(t, "_testdata/symlinktofolder", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[9])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[10])
pathEqualsTo(t, "_testdata/test.txt", l[11])
pathEqualsTo(t, "_testdata/test.txt.gz", l[12])

l, err = testdata.ReadDirRecursiveFiltered(FilterOutPrefixes("sub"), AndFilter(FilterOutSuffixes("3"), FilterOutPrefixes("fil"), FilterOutSuffixes(".gz")))
require.NoError(t, err)
l.Sort()
require.Len(t, l, 8)
require.Len(t, l, 12)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/folder", l[1])
pathEqualsTo(t, "_testdata/folder/.hidden", l[2])
pathEqualsTo(t, "_testdata/folder/subfolder", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[6])
pathEqualsTo(t, "_testdata/test.txt", l[7])

pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[4])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", l[5])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/.hidden", l[6])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder/subfolder", l[7])

pathEqualsTo(t, "_testdata/symlinktofolder", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[9])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[10])
pathEqualsTo(t, "_testdata/test.txt", l[11])

l, err = testdata.ReadDirRecursiveFiltered(OrFilter(FilterPrefixes("sub"), FilterSuffixes("tofolder")))
require.NoError(t, err)
l.Sort()
require.Len(t, l, 11)
require.Len(t, l, 12)
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder", l[2])
pathEqualsTo(t, "_testdata/symlinktofolder", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[6])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[7])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[8])
pathEqualsTo(t, "_testdata/test.txt", l[9])
pathEqualsTo(t, "_testdata/test.txt.gz", l[10])
pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/.hidden", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[6])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[7])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[8])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", l[9])
pathEqualsTo(t, "_testdata/test.txt", l[10])
pathEqualsTo(t, "_testdata/test.txt.gz", l[11])

l, err = testdata.ReadDirRecursiveFiltered(nil, FilterNames("folder"))
require.NoError(t, err)
l.Sort()
require.Len(t, l, 1)
require.Len(t, l, 2)
pathEqualsTo(t, "_testdata/folder", l[0])
pathEqualsTo(t, "_testdata/folder_containing_symlinks/folder", l[1])

l, err = testdata.ReadDirRecursiveFiltered(FilterNames("symlinktofolder"), FilterOutNames(".hidden"))
require.NoError(t, err)
require.Len(t, l, 9)
require.Len(t, l, 10)
l.Sort()
pathEqualsTo(t, "_testdata/anotherFile", l[0])
pathEqualsTo(t, "_testdata/file", l[1])
pathEqualsTo(t, "_testdata/folder", l[2])
pathEqualsTo(t, "_testdata/symlinktofolder", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[6])
pathEqualsTo(t, "_testdata/test.txt", l[7])
pathEqualsTo(t, "_testdata/test.txt.gz", l[8])
pathEqualsTo(t, "_testdata/folder_containing_symlinks", l[3])
pathEqualsTo(t, "_testdata/symlinktofolder", l[4])
pathEqualsTo(t, "_testdata/symlinktofolder/file2", l[5])
pathEqualsTo(t, "_testdata/symlinktofolder/file3", l[6])
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder", l[7])
pathEqualsTo(t, "_testdata/test.txt", l[8])
pathEqualsTo(t, "_testdata/test.txt.gz", l[9])
}

0 comments on commit c3afb8e

Please sign in to comment.