2017-03-29 21:58:25 +00:00
|
|
|
package swift
|
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
2017-03-29 21:58:25 +00:00
|
|
|
|
2023-04-20 21:02:56 +00:00
|
|
|
"github.com/restic/restic/internal/backend/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
var configTests = []test.ConfigTestData[Config]{
|
2017-06-05 22:33:25 +00:00
|
|
|
{
|
|
|
|
"swift:cnt1:/",
|
|
|
|
Config{
|
|
|
|
Container: "cnt1",
|
|
|
|
Prefix: "",
|
2017-06-11 11:46:54 +00:00
|
|
|
Connections: 5,
|
2017-06-05 22:33:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"swift:cnt2:/prefix",
|
|
|
|
Config{Container: "cnt2",
|
|
|
|
Prefix: "prefix",
|
2017-06-11 11:46:54 +00:00
|
|
|
Connections: 5,
|
2017-06-05 22:33:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"swift:cnt3:/prefix/longer",
|
|
|
|
Config{Container: "cnt3",
|
|
|
|
Prefix: "prefix/longer",
|
2017-06-11 11:46:54 +00:00
|
|
|
Connections: 5,
|
2017-06-05 22:33:25 +00:00
|
|
|
},
|
|
|
|
},
|
2017-03-29 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 08:13:03 +00:00
|
|
|
func TestParseConfig(t *testing.T) {
|
2023-04-20 21:02:56 +00:00
|
|
|
test.ParseConfigTester(t, ParseConfig, configTests)
|
2017-03-29 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|