8656bd2bb0
This change allows remotes to be created on the fly without a config file by using the remote type prefixed with a : as the remote name, Eg :s3: to make an s3 remote. This assumes the user is supplying the backend config via command line flags or environment variables.
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package fspath
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
for _, test := range []struct {
|
|
in, wantConfigName, wantFsPath string
|
|
}{
|
|
{"", "", ""},
|
|
{"/path/to/file", "", "/path/to/file"},
|
|
{"path/to/file", "", "path/to/file"},
|
|
{"remote:path/to/file", "remote", "path/to/file"},
|
|
{"remote:/path/to/file", "remote", "/path/to/file"},
|
|
{":backend:/path/to/file", ":backend", "/path/to/file"},
|
|
} {
|
|
gotConfigName, gotFsPath := Parse(test.in)
|
|
assert.Equal(t, test.wantConfigName, gotConfigName)
|
|
assert.Equal(t, test.wantFsPath, gotFsPath)
|
|
}
|
|
}
|
|
|
|
func TestSplit(t *testing.T) {
|
|
for _, test := range []struct {
|
|
remote, wantParent, wantLeaf string
|
|
}{
|
|
{"", "", ""},
|
|
|
|
{"remote:", "remote:", ""},
|
|
{"remote:potato", "remote:", "potato"},
|
|
{"remote:/", "remote:/", ""},
|
|
{"remote:/potato", "remote:/", "potato"},
|
|
{"remote:/potato/potato", "remote:/potato/", "potato"},
|
|
{"remote:potato/sausage", "remote:potato/", "sausage"},
|
|
|
|
{":remote:", ":remote:", ""},
|
|
{":remote:potato", ":remote:", "potato"},
|
|
{":remote:/", ":remote:/", ""},
|
|
{":remote:/potato", ":remote:/", "potato"},
|
|
{":remote:/potato/potato", ":remote:/potato/", "potato"},
|
|
{":remote:potato/sausage", ":remote:potato/", "sausage"},
|
|
|
|
{"/", "/", ""},
|
|
{"/root", "/", "root"},
|
|
{"/a/b", "/a/", "b"},
|
|
{"root", "", "root"},
|
|
{"a/b", "a/", "b"},
|
|
{"root/", "root/", ""},
|
|
{"a/b/", "a/b/", ""},
|
|
} {
|
|
gotParent, gotLeaf := Split(test.remote)
|
|
assert.Equal(t, test.wantParent, gotParent, test.remote)
|
|
assert.Equal(t, test.wantLeaf, gotLeaf, test.remote)
|
|
assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote))
|
|
}
|
|
}
|