@@ -12,13 +12,13 @@ import (
1212 "github.com/werf/werf/pkg/util"
1313)
1414
15- type entry struct {
15+ type expandPathTest struct {
1616 path string
1717 expectedPathFormat string
1818}
1919
2020var _ = DescribeTable ("expand path" ,
21- func (e entry ) {
21+ func (e expandPathTest ) {
2222 usr , err := user .Current ()
2323 Ω (err ).ShouldNot (HaveOccurred ())
2424
@@ -28,24 +28,56 @@ var _ = DescribeTable("expand path",
2828 expectedPath := fmt .Sprintf (e .expectedPathFormat , usr .HomeDir , wd )
2929 Ω (util .ExpandPath (filepath .FromSlash (e .path ))).Should (Equal (filepath .FromSlash (expectedPath )))
3030 },
31- Entry ("~" , entry {
31+ Entry ("~" , expandPathTest {
3232 path : "~" ,
3333 expectedPathFormat : "%[1]s" ,
3434 }),
35- Entry ("~/" , entry {
35+ Entry ("~/" , expandPathTest {
3636 path : "~/" ,
3737 expectedPathFormat : "%[1]s" ,
3838 }),
39- Entry ("~/path" , entry {
39+ Entry ("~/path" , expandPathTest {
4040 path : "~/path" ,
4141 expectedPathFormat : "%[1]s/path" ,
4242 }),
43- Entry ("path" , entry {
43+ Entry ("path" , expandPathTest {
4444 path : "path" ,
4545 expectedPathFormat : "%[2]s/path" ,
4646 }),
47- Entry ("path1/../path2" , entry {
47+ Entry ("path1/../path2" , expandPathTest {
4848 path : "path1/../path2" ,
4949 expectedPathFormat : "%[2]s/path2" ,
5050 }),
5151)
52+
53+ type splitPathTest struct {
54+ path string
55+ expectedPathParts []string
56+ }
57+
58+ var _ = DescribeTable ("split path" ,
59+ func (t splitPathTest ) {
60+ parts := util .SplitFilepath (t .path )
61+ Expect (parts ).To (Equal (t .expectedPathParts ))
62+ },
63+ Entry ("root path" , splitPathTest {
64+ path : "/" ,
65+ expectedPathParts : nil ,
66+ }),
67+ Entry ("unnormalized root path" , splitPathTest {
68+ path : "////" ,
69+ expectedPathParts : nil ,
70+ }),
71+ Entry ("empty path" , splitPathTest {
72+ path : "" ,
73+ expectedPathParts : nil ,
74+ }),
75+ Entry ("absolute path" , splitPathTest {
76+ path : "/path/to/dir/or/file" ,
77+ expectedPathParts : []string {"path" , "to" , "dir" , "or" , "file" },
78+ }),
79+ Entry ("relative path" , splitPathTest {
80+ path : "path/to/dir/or/file" ,
81+ expectedPathParts : []string {"path" , "to" , "dir" , "or" , "file" },
82+ }),
83+ )
0 commit comments