backend/rest: Ensure base URL ends with slash

This makes it easier for rclone.
This commit is contained in:
Alexander Neumann 2018-03-15 21:37:18 +01:00
parent 4d5c7a8749
commit 17312d3a98
3 changed files with 30 additions and 16 deletions

View File

@ -681,7 +681,7 @@ return JSON. Any different value for this header means API version 1.
The placeholder ``{path}`` in this document is a path to the repository, so
that multiple different repositories can be accessed. The default path is
``/``.
``/``. The path must end with a slash.
POST {path}?create=true
=======================

View File

@ -32,6 +32,10 @@ func ParseConfig(s string) (interface{}, error) {
}
s = s[5:]
if !strings.HasSuffix(s, "/") {
s += "/"
}
u, err := url.Parse(s)
if err != nil {

View File

@ -19,24 +19,34 @@ var configTests = []struct {
s string
cfg Config
}{
{"rest:http://localhost:1234", Config{
URL: parseURL("http://localhost:1234"),
Connections: 5,
}},
{
s: "rest:http://localhost:1234",
cfg: Config{
URL: parseURL("http://localhost:1234/"),
Connections: 5,
},
},
{
s: "rest:http://localhost:1234/",
cfg: Config{
URL: parseURL("http://localhost:1234/"),
Connections: 5,
},
},
}
func TestParseConfig(t *testing.T) {
for i, test := range configTests {
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d:%s failed: %v", i, test.s, err)
continue
}
for _, test := range configTests {
t.Run("", func(t *testing.T) {
cfg, err := ParseConfig(test.s)
if err != nil {
t.Fatalf("%s failed: %v", test.s, err)
}
if !reflect.DeepEqual(cfg, test.cfg) {
t.Errorf("test %d:\ninput:\n %s\n wrong config, want:\n %v\ngot:\n %v",
i, test.s, test.cfg, cfg)
continue
}
if !reflect.DeepEqual(cfg, test.cfg) {
t.Fatalf("\ninput: %s\n wrong config, want:\n %v\ngot:\n %v",
test.s, test.cfg, cfg)
}
})
}
}