mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
backend: let ParseConfig return a Config pointer
In order to change the backend initialization in `global.go` to be able to generically call cfg.ApplyEnvironment() for supported backends, the `interface{}` returned by `ParseConfig` must contain a pointer to the configuration. An alternative would be to use reflection to convert the type from `interface{}(Config)` to `interface{}(*Config)` (from value to pointer type). However, this would just complicate the type mess further.
This commit is contained in:
@@ -27,12 +27,12 @@ func init() {
|
||||
}
|
||||
|
||||
// ParseConfig parses a local backend config.
|
||||
func ParseConfig(s string) (Config, error) {
|
||||
func ParseConfig(s string) (*Config, error) {
|
||||
if !strings.HasPrefix(s, "local:") {
|
||||
return Config{}, errors.New(`invalid format, prefix "local" not found`)
|
||||
return nil, errors.New(`invalid format, prefix "local" not found`)
|
||||
}
|
||||
|
||||
cfg := NewConfig()
|
||||
cfg.Path = s[6:]
|
||||
return cfg, nil
|
||||
return &cfg, nil
|
||||
}
|
||||
|
18
internal/backend/local/config_test.go
Normal file
18
internal/backend/local/config_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
)
|
||||
|
||||
var configTests = []test.ConfigTestData[Config]{
|
||||
{S: "local:/some/path", Cfg: Config{
|
||||
Path: "/some/path",
|
||||
Connections: 2,
|
||||
}},
|
||||
}
|
||||
|
||||
func TestParseConfig(t *testing.T) {
|
||||
test.ParseConfigTester(t, ParseConfig, configTests)
|
||||
}
|
@@ -15,7 +15,7 @@ import (
|
||||
func newTestSuite(t testing.TB) *test.Suite[local.Config] {
|
||||
return &test.Suite[local.Config]{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (local.Config, error) {
|
||||
NewConfig: func() (*local.Config, error) {
|
||||
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-local-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -23,7 +23,7 @@ func newTestSuite(t testing.TB) *test.Suite[local.Config] {
|
||||
|
||||
t.Logf("create new backend at %v", dir)
|
||||
|
||||
cfg := local.Config{
|
||||
cfg := &local.Config{
|
||||
Path: dir,
|
||||
Connections: 2,
|
||||
}
|
||||
|
Reference in New Issue
Block a user