/
path_windows_test.go
58 lines (53 loc) · 1.6 KB
/
path_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build windows
package util_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/werf/werf/pkg/util"
)
type splitPathTest struct {
path string
expectedPathParts []string
}
var _ = DescribeTable("split windows path",
func(t splitPathTest) {
parts := util.SplitFilepath(t.path)
Expect(parts).To(Equal(t.expectedPathParts))
},
Entry("UNC absolute path", splitPathTest{
path: `\\Server2\Share\Test\Foo.txt`,
expectedPathParts: []string{"Server2", "Share", "Test", "Foo.txt"},
}),
Entry("UNC absolute non-normalized path", splitPathTest{
path: `\\\\\\Server2\\\Share\\\Test\Foo.txt`,
expectedPathParts: []string{"Server2", "Share", "Test", "Foo.txt"},
}),
Entry("UNC root path", splitPathTest{
path: `\\`,
expectedPathParts: nil,
}),
Entry("root disk path", splitPathTest{
path: `D:\`,
expectedPathParts: []string{`D:`},
}),
Entry("unnormalized root disk path", splitPathTest{
path: `D:\\\\\\`,
expectedPathParts: []string{`D:`},
}),
Entry("empty path", splitPathTest{
path: "",
expectedPathParts: nil,
}),
Entry("absolute path to file", splitPathTest{
path: `D:\path\to\file`,
expectedPathParts: []string{`D:`, "path", "to", "file"},
}),
Entry("absolute path to dir", splitPathTest{
path: `D:\path\to\dir\`,
expectedPathParts: []string{`D:`, "path", "to", "dir"},
}),
Entry("relative path", splitPathTest{
path: `path\to\dir\or\file`,
expectedPathParts: []string{"path", "to", "dir", "or", "file"},
}),
)