forked from TrueCloudLab/restic
strip off the trailing slash for the object prefix
This commit is contained in:
parent
48f85fbb09
commit
74608531c7
2 changed files with 23 additions and 1 deletions
|
@ -63,7 +63,7 @@ func ParseConfig(s string) (interface{}, error) {
|
||||||
}
|
}
|
||||||
cfg.Bucket = path[0]
|
cfg.Bucket = path[0]
|
||||||
if len(path) > 1 {
|
if len(path) > 1 {
|
||||||
cfg.Prefix = path[1]
|
cfg.Prefix = strings.TrimRight(path[1], "/")
|
||||||
} else {
|
} else {
|
||||||
cfg.Prefix = defaultPrefix
|
cfg.Prefix = defaultPrefix
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,11 @@ var configTests = []struct {
|
||||||
Bucket: "bucketname",
|
Bucket: "bucketname",
|
||||||
Prefix: "prefix/directory",
|
Prefix: "prefix/directory",
|
||||||
}},
|
}},
|
||||||
|
{"s3://eu-central-1/bucketname/prefix/directory/", Config{
|
||||||
|
Endpoint: "eu-central-1",
|
||||||
|
Bucket: "bucketname",
|
||||||
|
Prefix: "prefix/directory",
|
||||||
|
}},
|
||||||
{"s3:eu-central-1/foobar", Config{
|
{"s3:eu-central-1/foobar", Config{
|
||||||
Endpoint: "eu-central-1",
|
Endpoint: "eu-central-1",
|
||||||
Bucket: "foobar",
|
Bucket: "foobar",
|
||||||
|
@ -36,6 +41,11 @@ var configTests = []struct {
|
||||||
Bucket: "foobar",
|
Bucket: "foobar",
|
||||||
Prefix: "prefix/directory",
|
Prefix: "prefix/directory",
|
||||||
}},
|
}},
|
||||||
|
{"s3:eu-central-1/foobar/prefix/directory/", Config{
|
||||||
|
Endpoint: "eu-central-1",
|
||||||
|
Bucket: "foobar",
|
||||||
|
Prefix: "prefix/directory",
|
||||||
|
}},
|
||||||
{"s3:https://hostname:9999/foobar", Config{
|
{"s3:https://hostname:9999/foobar", Config{
|
||||||
Endpoint: "hostname:9999",
|
Endpoint: "hostname:9999",
|
||||||
Bucket: "foobar",
|
Bucket: "foobar",
|
||||||
|
@ -52,12 +62,24 @@ var configTests = []struct {
|
||||||
Prefix: "restic",
|
Prefix: "restic",
|
||||||
UseHTTP: true,
|
UseHTTP: true,
|
||||||
}},
|
}},
|
||||||
|
{"s3:http://hostname:9999/foobar/", Config{
|
||||||
|
Endpoint: "hostname:9999",
|
||||||
|
Bucket: "foobar",
|
||||||
|
Prefix: "",
|
||||||
|
UseHTTP: true,
|
||||||
|
}},
|
||||||
{"s3:http://hostname:9999/bucket/prefix/directory", Config{
|
{"s3:http://hostname:9999/bucket/prefix/directory", Config{
|
||||||
Endpoint: "hostname:9999",
|
Endpoint: "hostname:9999",
|
||||||
Bucket: "bucket",
|
Bucket: "bucket",
|
||||||
Prefix: "prefix/directory",
|
Prefix: "prefix/directory",
|
||||||
UseHTTP: true,
|
UseHTTP: true,
|
||||||
}},
|
}},
|
||||||
|
{"s3:http://hostname:9999/bucket/prefix/directory/", Config{
|
||||||
|
Endpoint: "hostname:9999",
|
||||||
|
Bucket: "bucket",
|
||||||
|
Prefix: "prefix/directory",
|
||||||
|
UseHTTP: true,
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseConfig(t *testing.T) {
|
func TestParseConfig(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue