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