mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
backend: let ParseConfig return concrete type
This commit is contained in:
@@ -30,12 +30,11 @@ func newAzureTestSuite(t testing.TB) *test.Suite {
|
||||
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (interface{}, error) {
|
||||
azcfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := azcfg.(azure.Config)
|
||||
cfg.AccountName = os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_NAME")
|
||||
cfg.AccountKey = options.NewSecretString(os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_KEY"))
|
||||
cfg.Prefix = fmt.Sprintf("test-%d", time.Now().UnixNano())
|
||||
@@ -141,12 +140,11 @@ func TestUploadLargeFile(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
azcfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := azcfg.(azure.Config)
|
||||
cfg.AccountName = os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_NAME")
|
||||
cfg.AccountKey = options.NewSecretString(os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_KEY"))
|
||||
cfg.Prefix = fmt.Sprintf("test-upload-large-%d", time.Now().UnixNano())
|
||||
|
@@ -34,9 +34,9 @@ func init() {
|
||||
|
||||
// ParseConfig parses the string s and extracts the azure config. The
|
||||
// configuration format is azure:containerName:/[prefix].
|
||||
func ParseConfig(s string) (interface{}, error) {
|
||||
func ParseConfig(s string) (Config, error) {
|
||||
if !strings.HasPrefix(s, "azure:") {
|
||||
return nil, errors.New("azure: invalid format")
|
||||
return Config{}, errors.New("azure: invalid format")
|
||||
}
|
||||
|
||||
// strip prefix "azure:"
|
||||
@@ -46,7 +46,7 @@ func ParseConfig(s string) (interface{}, error) {
|
||||
// remainder as prefix
|
||||
container, prefix, colon := strings.Cut(s, ":")
|
||||
if !colon {
|
||||
return nil, errors.New("azure: invalid format: bucket name or path not found")
|
||||
return Config{}, errors.New("azure: invalid format: bucket name or path not found")
|
||||
}
|
||||
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
|
||||
cfg := NewConfig()
|
||||
|
Reference in New Issue
Block a user