restic/internal/backend/swift/config_test.go

68 lines
1.2 KiB
Go
Raw Normal View History

package swift
import "testing"
var configTests = []struct {
s string
cfg Config
}{
2017-06-05 22:33:25 +00:00
{
"swift:cnt1:/",
Config{
Container: "cnt1",
Prefix: "",
Connections: 5,
2017-06-05 22:33:25 +00:00
},
},
{
"swift:cnt2:/prefix",
Config{Container: "cnt2",
Prefix: "prefix",
Connections: 5,
2017-06-05 22:33:25 +00:00
},
},
{
"swift:cnt3:/prefix/longer",
Config{Container: "cnt3",
Prefix: "prefix/longer",
Connections: 5,
2017-06-05 22:33:25 +00:00
},
},
}
2017-05-01 08:13:03 +00:00
func TestParseConfig(t *testing.T) {
for _, test := range configTests {
t.Run("", func(t *testing.T) {
cfg, err := ParseConfig(test.s)
2017-05-01 08:13:03 +00:00
if err != nil {
t.Fatalf("parsing %q failed: %v", test.s, err)
}
2017-05-01 08:13:03 +00:00
if cfg != test.cfg {
t.Fatalf("wrong output for %q, want:\n %#v\ngot:\n %#v",
test.s, test.cfg, cfg)
}
})
}
}
var configTestsInvalid = []string{
"swift://hostname/container",
"swift:////",
"swift://",
"swift:////prefix",
"swift:container",
"swift:container:",
"swift:container/prefix",
}
func TestParseConfigInvalid(t *testing.T) {
for i, test := range configTestsInvalid {
_, err := ParseConfig(test)
if err == nil {
t.Errorf("test %d: invalid config %s did not return an error", i, test)
continue
}
}
}