Skip to content

Commit 710584e

Browse files
Fix bug
Signed-off-by: OhioDschungel6 <39698795+ohiodschungel6@users.noreply.github.com>
1 parent 916d962 commit 710584e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

utils/filesystem.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func GetAllFilePaths(dirRoot string, pathsIgnored []string) ([]string, error) {
4141

4242
path = filepath.ToSlash(path)
4343
shortPath := strings.TrimPrefix(path, prefix)
44+
if !strings.HasPrefix(shortPath, "/") {
45+
//This happens if the dirRoot is "."
46+
shortPath = "/" + shortPath
47+
}
4448

4549
// don't include path if it should be ignored
4650
if pathsIgnored != nil && ShouldIgnore(shortPath, pathsIgnored) {

utils/filesystem_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ func TestFilesystemCanGetSliceOfFolderContents(t *testing.T) {
4242
}
4343
}
4444

45+
func TestFilesystemCanGetSliceOfFolderContentsFromRelativeDir(t *testing.T) {
46+
t.Chdir("../testdata/project1/")
47+
48+
filePaths, err := GetAllFilePaths(".", nil)
49+
if err != nil {
50+
t.Fatalf("expected filePaths, got error: %v", err)
51+
}
52+
if filePaths == nil {
53+
t.Fatalf("expected non-nil filePaths, got nil")
54+
}
55+
// should only be 5 files
56+
// symbolic link in project1/symbolic-link should be ignored
57+
if len(filePaths) != 5 {
58+
t.Fatalf("expected %v, got %v", 5, len(filePaths))
59+
}
60+
61+
// should be in alphabetical order, with files prefixed with '/'
62+
if filePaths[0] != "/emptyfile.testdata.txt" {
63+
t.Errorf("expected %v, got %v", "/emptyfile.testdata.txt", filePaths[0])
64+
}
65+
if filePaths[1] != "/file1.testdata.txt" {
66+
t.Errorf("expected %v, got %v", "/file1.testdata.txt", filePaths[1])
67+
}
68+
if filePaths[2] != "/file3.testdata.txt" {
69+
t.Errorf("expected %v, got %v", "/file3.testdata.txt", filePaths[2])
70+
}
71+
if filePaths[3] != "/folder1/file4.testdata.txt" {
72+
t.Errorf("expected %v, got %v", "/folder1/file4.testdata.txt", filePaths[3])
73+
}
74+
if filePaths[4] != "/lastfile.testdata.txt" {
75+
t.Errorf("expected %v, got %v", "/lastfile.testdata.txt", filePaths[4])
76+
}
77+
}
78+
4579
func TestFilesystemGetAllFilePathsFailsForNonExistentDirectory(t *testing.T) {
4680
dirRoot := "./does/not/exist/"
4781

0 commit comments

Comments
 (0)