2018-01-13 00:30:54 +08:00
|
|
|
package fspath
|
2016-10-24 00:34:17 +08:00
|
|
|
|
|
|
|
import (
|
2017-02-23 05:24:04 +08:00
|
|
|
"fmt"
|
2016-10-24 00:34:17 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoteSplit(t *testing.T) {
|
|
|
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
remote, wantParent, wantLeaf string
|
|
|
|
}{
|
|
|
|
{"", "", ""},
|
2017-02-23 05:24:04 +08:00
|
|
|
{"remote:", "remote:", ""},
|
2016-10-24 00:34:17 +08:00
|
|
|
{"remote:potato", "remote:", "potato"},
|
2017-02-23 05:24:04 +08:00
|
|
|
{"remote:/", "remote:/", ""},
|
|
|
|
{"remote:/potato", "remote:/", "potato"},
|
|
|
|
{"remote:/potato/potato", "remote:/potato/", "potato"},
|
|
|
|
{"remote:potato/sausage", "remote:potato/", "sausage"},
|
|
|
|
{"/", "/", ""},
|
2016-10-24 00:34:17 +08:00
|
|
|
{"/root", "/", "root"},
|
2017-02-23 05:24:04 +08:00
|
|
|
{"/a/b", "/a/", "b"},
|
|
|
|
{"root", "", "root"},
|
|
|
|
{"a/b", "a/", "b"},
|
|
|
|
{"root/", "root/", ""},
|
|
|
|
{"a/b/", "a/b/", ""},
|
2016-10-24 00:34:17 +08:00
|
|
|
} {
|
|
|
|
gotParent, gotLeaf := RemoteSplit(test.remote)
|
|
|
|
assert.Equal(t, test.wantParent, gotParent, test.remote)
|
|
|
|
assert.Equal(t, test.wantLeaf, gotLeaf, test.remote)
|
2017-02-23 05:24:04 +08:00
|
|
|
assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote))
|
2016-10-24 00:34:17 +08:00
|
|
|
}
|
|
|
|
}
|