2015-12-28 14:51:24 +00:00
|
|
|
package s3
|
|
|
|
|
2022-11-27 17:09:59 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2023-04-20 21:02:56 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/backend/test"
|
2022-11-27 17:09:59 +00:00
|
|
|
)
|
2015-12-28 14:51:24 +00:00
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
var configTests = []test.ConfigTestData[Config]{
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3://eu-central-1/bucketname", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "eu-central-1",
|
|
|
|
Bucket: "bucketname",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-07 19:28:29 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3://eu-central-1/bucketname/", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "eu-central-1",
|
|
|
|
Bucket: "bucketname",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-14 14:40:15 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3://eu-central-1/bucketname/prefix/directory", Cfg: 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
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3://eu-central-1/bucketname/prefix/directory/", Cfg: 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
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:eu-central-1/foobar", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "eu-central-1",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-07 19:28:29 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:eu-central-1/foobar/", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "eu-central-1",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-14 14:40:15 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:eu-central-1/foobar/prefix/directory", Cfg: 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
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:eu-central-1/foobar/prefix/directory/", Cfg: 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
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:https://hostname:9999/foobar", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "hostname:9999",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2015-12-28 17:23:02 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:https://hostname:9999/foobar/", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "hostname:9999",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-14 14:40:15 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:http://hostname:9999/foobar", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "hostname:9999",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-05 22:17:39 +00:00
|
|
|
UseHTTP: true,
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-07 19:28:29 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:http://hostname:9999/foobar/", Cfg: Config{
|
2017-06-05 22:17:39 +00:00
|
|
|
Endpoint: "hostname:9999",
|
|
|
|
Bucket: "foobar",
|
2017-11-20 21:29:15 +00:00
|
|
|
Prefix: "",
|
2017-06-05 22:17:39 +00:00
|
|
|
UseHTTP: true,
|
2017-06-11 09:15:15 +00:00
|
|
|
Connections: 5,
|
2016-02-14 15:16:50 +00:00
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:http://hostname:9999/bucket/prefix/directory", Cfg: 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
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "s3:http://hostname:9999/bucket/prefix/directory/", Cfg: 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) {
|
2023-04-20 21:02:56 +00:00
|
|
|
test.ParseConfigTester(t, ParseConfig, configTests)
|
2015-12-28 14:51:24 +00:00
|
|
|
}
|
2022-11-27 17:09:59 +00:00
|
|
|
|
|
|
|
func TestParseError(t *testing.T) {
|
|
|
|
const prefix = "s3: invalid format,"
|
|
|
|
|
|
|
|
for _, s := range []string{"", "/", "//", "/bucket/prefix"} {
|
|
|
|
_, err := ParseConfig("s3://" + s)
|
|
|
|
if err == nil || !strings.HasPrefix(err.Error(), prefix) {
|
|
|
|
t.Errorf("expected %q, got %q", prefix, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|