restic/backend/s3/config_test.go

100 lines
2.2 KiB
Go
Raw Normal View History

2015-12-28 15:51:24 +01:00
package s3
import "testing"
2015-12-28 15:57:20 +01:00
var configTests = []struct {
2015-12-28 15:51:24 +01:00
s string
cfg Config
}{
{"s3://eu-central-1/bucketname", Config{
2015-12-29 11:24:08 +01:00
Endpoint: "eu-central-1",
Bucket: "bucketname",
Prefix: "restic",
}},
2016-02-14 15:40:15 +01:00
{"s3://eu-central-1/bucketname/", Config{
Endpoint: "eu-central-1",
Bucket: "bucketname",
Prefix: "",
}},
{"s3://eu-central-1/bucketname/prefix/directory", Config{
Endpoint: "eu-central-1",
Bucket: "bucketname",
Prefix: "prefix/directory",
2015-12-28 15:51:24 +01:00
}},
{"s3://eu-central-1/bucketname/prefix/directory/", Config{
Endpoint: "eu-central-1",
Bucket: "bucketname",
Prefix: "prefix/directory",
}},
2015-12-28 18:23:02 +01:00
{"s3:eu-central-1/foobar", Config{
2015-12-29 11:24:08 +01:00
Endpoint: "eu-central-1",
Bucket: "foobar",
Prefix: "restic",
}},
2016-02-14 15:40:15 +01:00
{"s3:eu-central-1/foobar/", Config{
Endpoint: "eu-central-1",
Bucket: "foobar",
Prefix: "",
}},
{"s3:eu-central-1/foobar/prefix/directory", Config{
Endpoint: "eu-central-1",
Bucket: "foobar",
Prefix: "prefix/directory",
2015-12-28 18:23:02 +01:00
}},
{"s3:eu-central-1/foobar/prefix/directory/", Config{
Endpoint: "eu-central-1",
Bucket: "foobar",
Prefix: "prefix/directory",
}},
2015-12-28 18:23:02 +01:00
{"s3:https://hostname:9999/foobar", Config{
2015-12-29 11:24:08 +01:00
Endpoint: "hostname:9999",
Bucket: "foobar",
Prefix: "restic",
2015-12-28 18:23:02 +01:00
}},
2016-02-14 15:40:15 +01:00
{"s3:https://hostname:9999/foobar/", Config{
Endpoint: "hostname:9999",
Bucket: "foobar",
Prefix: "",
}},
2015-12-28 18:23:02 +01:00
{"s3:http://hostname:9999/foobar", Config{
2015-12-29 11:24:08 +01:00
Endpoint: "hostname:9999",
Bucket: "foobar",
Prefix: "restic",
UseHTTP: true,
}},
{"s3:http://hostname:9999/foobar/", Config{
Endpoint: "hostname:9999",
Bucket: "foobar",
Prefix: "",
UseHTTP: true,
}},
{"s3:http://hostname:9999/bucket/prefix/directory", Config{
Endpoint: "hostname:9999",
Bucket: "bucket",
Prefix: "prefix/directory",
2015-12-29 11:24:08 +01:00
UseHTTP: true,
2015-12-28 15:51:24 +01:00
}},
{"s3:http://hostname:9999/bucket/prefix/directory/", Config{
Endpoint: "hostname:9999",
Bucket: "bucket",
Prefix: "prefix/directory",
UseHTTP: true,
}},
2015-12-28 15:51:24 +01:00
}
func TestParseConfig(t *testing.T) {
2015-12-28 15:57:20 +01:00
for i, test := range configTests {
2015-12-28 15:51:24 +01:00
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d failed: %v", i, err)
continue
}
if cfg != test.cfg {
t.Errorf("test %d: wrong config, want:\n %v\ngot:\n %v",
i, test.cfg, cfg)
continue
}
}
}