Skip to content

Commit 75f5b81

Browse files
committed
more testing
1 parent 1e9f82a commit 75f5b81

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

utils/filesystem/filepath.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func FilePathParentsOnFilesystem(fs FS, fp string) (parents []string) {
3131
return
3232
}
3333
path := elements[0]
34+
if path == "" {
35+
elements = elements[1:]
36+
if len(elements) <= 1 {
37+
return
38+
}
39+
path = elements[0]
40+
}
3441
parents = append(parents, path)
3542
for i := 1; i < len(elements)-1; i++ {
3643
path = strings.Join([]string{path, elements[i]}, string(fs.PathSeparator()))

utils/filesystem/filepath_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/ARM-software/golang-utils/utils/commonerrors"
1414
"github.com/ARM-software/golang-utils/utils/commonerrors/errortest"
15+
"github.com/ARM-software/golang-utils/utils/platform"
1516
)
1617

1718
func TestFilepathStem(t *testing.T) {
@@ -30,24 +31,52 @@ func TestFilepathStem(t *testing.T) {
3031
}
3132

3233
func TestFilepathParents(t *testing.T) {
33-
34-
tests := []struct {
34+
type PathTest struct {
3535
path string
3636
expectedParents []string
37-
}{
37+
}
38+
tests := []PathTest{
3839
{},
3940
{
4041
path: " ",
4142
expectedParents: nil,
4243
},
44+
{
45+
path: "/",
46+
expectedParents: nil,
47+
},
48+
{
49+
path: ".",
50+
expectedParents: nil,
51+
},
52+
{
53+
path: "./",
54+
expectedParents: nil,
55+
},
56+
{
57+
path: "./blah",
58+
expectedParents: []string{"."},
59+
},
4360
{
4461
path: filepath.Join("a", "great", "fake", "path", "blah"),
4562
expectedParents: []string{"a", filepath.Join("a", "great"), filepath.Join("a", "great", "fake"), filepath.Join("a", "great", "fake", "path")},
4663
},
4764
{
65+
path: "/foo/bar/setup.py",
66+
expectedParents: []string{`foo`, filepath.Join(`foo`, `bar`)},
67+
},
68+
}
69+
70+
if platform.IsWindows() {
71+
tests = append(tests, PathTest{
4872
path: "C:/foo/bar/setup.py",
4973
expectedParents: []string{"C:", filepath.Join(`C:`, `\foo`), filepath.Join(`C:`, `\foo`, `bar`)},
50-
},
74+
})
75+
} else {
76+
tests = append(tests, PathTest{
77+
path: "C:/foo/bar/setup.py",
78+
expectedParents: []string{"C:", filepath.Join(`C:`, `foo`), filepath.Join(`C:`, `foo`, `bar`)},
79+
})
5180
}
5281
for _, tt := range tests {
5382
t.Run(tt.path, func(t *testing.T) {

0 commit comments

Comments
 (0)