Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: panic when calling SplitFilepath on windows
Unix unit test improved. Windows unit test included. Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
- Loading branch information
1 parent
189ec01
commit 78c10d2
Showing
3 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"}, | ||
}), | ||
) |