Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions utils/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func GetAllFilePaths(dirRoot string, pathsIgnored []string) ([]string, error) {

path = filepath.ToSlash(path)
shortPath := strings.TrimPrefix(path, prefix)
if !strings.HasPrefix(shortPath, "/") {
//This happens if the dirRoot is "."
shortPath = "/" + shortPath
}

// don't include path if it should be ignored
if pathsIgnored != nil && ShouldIgnore(shortPath, pathsIgnored) {
Expand Down
34 changes: 34 additions & 0 deletions utils/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@
}
}

func TestFilesystemCanGetSliceOfFolderContentsFromRelativeDir(t *testing.T) {
t.Chdir("../testdata/project1/")

Check failure on line 46 in utils/filesystem_test.go

View workflow job for this annotation

GitHub Actions / tests

t.Chdir undefined (type *testing.T has no field or method Chdir)

filePaths, err := GetAllFilePaths(".", nil)
if err != nil {
t.Fatalf("expected filePaths, got error: %v", err)
}
if filePaths == nil {
t.Fatalf("expected non-nil filePaths, got nil")
}
// should only be 5 files
// symbolic link in project1/symbolic-link should be ignored
if len(filePaths) != 5 {
t.Fatalf("expected %v, got %v", 5, len(filePaths))
}

// should be in alphabetical order, with files prefixed with '/'
if filePaths[0] != "/emptyfile.testdata.txt" {
t.Errorf("expected %v, got %v", "/emptyfile.testdata.txt", filePaths[0])
}
if filePaths[1] != "/file1.testdata.txt" {
t.Errorf("expected %v, got %v", "/file1.testdata.txt", filePaths[1])
}
if filePaths[2] != "/file3.testdata.txt" {
t.Errorf("expected %v, got %v", "/file3.testdata.txt", filePaths[2])
}
if filePaths[3] != "/folder1/file4.testdata.txt" {
t.Errorf("expected %v, got %v", "/folder1/file4.testdata.txt", filePaths[3])
}
if filePaths[4] != "/lastfile.testdata.txt" {
t.Errorf("expected %v, got %v", "/lastfile.testdata.txt", filePaths[4])
}
}

func TestFilesystemGetAllFilePathsFailsForNonExistentDirectory(t *testing.T) {
dirRoot := "./does/not/exist/"

Expand Down
Loading