fspath: factor Split into SplitFs and Split #4996

This commit is contained in:
Nick Craig-Wood
2021-02-10 14:26:30 +00:00
parent 8a46dd1b57
commit 71554c1371
2 changed files with 63 additions and 5 deletions

View File

@@ -324,6 +324,47 @@ func TestParse(t *testing.T) {
}
}
func TestSplitFs(t *testing.T) {
for _, test := range []struct {
remote, wantRemoteName, wantRemotePath string
wantErr error
}{
{"", "", "", errCantBeEmpty},
{"remote:", "remote:", "", nil},
{"remote:potato", "remote:", "potato", nil},
{"remote:/", "remote:", "/", nil},
{"remote:/potato", "remote:", "/potato", nil},
{"remote:/potato/potato", "remote:", "/potato/potato", nil},
{"remote:potato/sausage", "remote:", "potato/sausage", nil},
{"rem.ote:potato/sausage", "", "", errInvalidCharacters},
{":remote:", ":remote:", "", nil},
{":remote:potato", ":remote:", "potato", nil},
{":remote:/", ":remote:", "/", nil},
{":remote:/potato", ":remote:", "/potato", nil},
{":remote:/potato/potato", ":remote:", "/potato/potato", nil},
{":remote:potato/sausage", ":remote:", "potato/sausage", nil},
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
{"/", "", "/", nil},
{"/root", "", "/root", nil},
{"/a/b", "", "/a/b", nil},
{"root", "", "root", nil},
{"a/b", "", "a/b", nil},
{"root/", "", "root/", nil},
{"a/b/", "", "a/b/", nil},
} {
gotRemoteName, gotRemotePath, gotErr := SplitFs(test.remote)
assert.Equal(t, test.wantErr, gotErr)
assert.Equal(t, test.wantRemoteName, gotRemoteName, test.remote)
assert.Equal(t, test.wantRemotePath, gotRemotePath, test.remote)
if gotErr == nil {
assert.Equal(t, test.remote, gotRemoteName+gotRemotePath, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotRemoteName, gotRemotePath, test.remote))
}
}
}
func TestSplit(t *testing.T) {
for _, test := range []struct {
remote, wantParent, wantLeaf string