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
|
|
|
{
|
2023-04-21 19:11:33 +00:00
|
|
|
S: "swift:cnt1:/",
|
|
|
|
Cfg: Config{
|
2017-06-05 22:33:25 +00:00
|
|
|
Container: "cnt1",
|
|
|
|
Prefix: "",
|
2017-06-11 11:46:54 +00:00
|
|
|
Connections: 5,
|
2017-06-05 22:33:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-21 19:11:33 +00:00
|
|
|
S: "swift:cnt2:/prefix",
|
|
|
|
Cfg: Config{Container: "cnt2",
|
2017-06-05 22:33:25 +00:00
|
|
|
Prefix: "prefix",
|
2017-06-11 11:46:54 +00:00
|
|
|
Connections: 5,
|
2017-06-05 22:33:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-21 19:11:33 +00:00
|
|
|
S: "swift:cnt3:/prefix/longer",
|
|
|
|
Cfg: Config{Container: "cnt3",
|
2017-06-05 22:33:25 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|