2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00:00
restic/internal/backend/b2/config_test.go

82 lines
1.6 KiB
Go
Raw Normal View History

package b2
import (
"testing"
"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{
Bucket: "bucketname",
Prefix: "",
Connections: 5,
}},
2023-04-21 19:11:33 +00:00
{S: "b2:bucketname:", Cfg: Config{
Bucket: "bucketname",
Prefix: "",
Connections: 5,
}},
2023-04-21 19:11:33 +00:00
{S: "b2:bucketname:/prefix/directory", Cfg: Config{
Bucket: "bucketname",
Prefix: "prefix/directory",
Connections: 5,
}},
2023-04-21 19:11:33 +00:00
{S: "b2:foobar", Cfg: Config{
Bucket: "foobar",
Prefix: "",
Connections: 5,
}},
2023-04-21 19:11:33 +00:00
{S: "b2:foobar:", Cfg: Config{
Bucket: "foobar",
Prefix: "",
Connections: 5,
}},
2023-04-21 19:11:33 +00:00
{S: "b2:foobar:/", Cfg: Config{
Bucket: "foobar",
Prefix: "",
Connections: 5,
}},
}
func TestParseConfig(t *testing.T) {
test.ParseConfigTester(t, ParseConfig, configTests)
}
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())
}
})
}
}