2017-05-28 08:19:01 +00:00
|
|
|
package b2
|
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
2017-05-28 08:19:01 +00:00
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
"github.com/restic/restic/internal/backend/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
var configTests = []test.ConfigTestData[Config]{
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:bucketname", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "bucketname",
|
|
|
|
Prefix: "",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:bucketname:", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "bucketname",
|
|
|
|
Prefix: "",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:bucketname:/prefix/directory", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "bucketname",
|
|
|
|
Prefix: "prefix/directory",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:foobar", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "foobar",
|
|
|
|
Prefix: "",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:foobar:", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "foobar",
|
|
|
|
Prefix: "",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
2023-04-21 19:11:33 +00:00
|
|
|
{S: "b2:foobar:/", Cfg: Config{
|
2017-05-28 08:19:01 +00:00
|
|
|
Bucket: "foobar",
|
|
|
|
Prefix: "",
|
|
|
|
Connections: 5,
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig(t *testing.T) {
|
2023-04-20 21:02:56 +00:00
|
|
|
test.ParseConfigTester(t, ParseConfig, configTests)
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var invalidConfigTests = []struct {
|
|
|
|
s string
|
|
|
|
err string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"b2",
|
|
|
|
"invalid format, want: b2:bucket-name[:path]",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"b2:",
|
|
|
|
"bucket name not found",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"b2:bucket_name",
|
|
|
|
"bucket name contains invalid characters, allowed are: a-z, 0-9, dash (-)",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"b2:bucketname/prefix/directory/",
|
|
|
|
"bucket name contains invalid characters, allowed are: a-z, 0-9, dash (-)",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidConfig(t *testing.T) {
|
|
|
|
for _, test := range invalidConfigTests {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
cfg, err := ParseConfig(test.s)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected error not found for invalid config: %v, cfg is:\n%#v", test.s, cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err.Error() != test.err {
|
|
|
|
t.Fatalf("unexpected error found, want:\n %v\ngot:\n %v", test.err, err.Error())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|