backend: unify NewFs path handling for wrapping remotes

Use the same function to join the root paths for the wrapping remotes
alias, cache and crypt.
The new function fspath.JoinRootPath is equivalent to path.Join, but if
the first non empty element starts with "//", this is preserved to allow
Windows network path to be used in these remotes.
This commit is contained in:
Fabian Möller
2018-10-10 17:50:27 +01:00
committed by Nick Craig-Wood
parent 411a6cc472
commit 1a40bceb1d
5 changed files with 54 additions and 13 deletions
+29
View File
@@ -58,3 +58,32 @@ func TestSplit(t *testing.T) {
assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote))
}
}
func TestJoinRootPath(t *testing.T) {
for _, test := range []struct {
elements []string
want string
}{
{nil, ""},
{[]string{""}, ""},
{[]string{"/"}, "/"},
{[]string{"/", "/"}, "/"},
{[]string{"/", "//"}, "/"},
{[]string{"/root", ""}, "/root"},
{[]string{"/root", "/"}, "/root"},
{[]string{"/root", "//"}, "/root"},
{[]string{"/a/b"}, "/a/b"},
{[]string{"//", "/"}, "//"},
{[]string{"//server", "path"}, "//server/path"},
{[]string{"//server/sub", "path"}, "//server/sub/path"},
{[]string{"//server", "//path"}, "//server/path"},
{[]string{"//server/sub", "//path"}, "//server/sub/path"},
{[]string{"", "//", "/"}, "//"},
{[]string{"", "//server", "path"}, "//server/path"},
{[]string{"", "//server/sub", "path"}, "//server/sub/path"},
{[]string{"", "//server", "//path"}, "//server/path"},
{[]string{"", "//server/sub", "//path"}, "//server/sub/path"},
} {
got := JoinRootPath(test.elements...)
assert.Equal(t, test.want, got)
}
}