mirror of
https://github.com/restic/restic.git
synced 2026-07-07 07:45:10 +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:
@@ -11,7 +11,7 @@ type ConfigTestData[C comparable] struct {
|
||||
Cfg C
|
||||
}
|
||||
|
||||
func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (C, error), tests []ConfigTestData[C]) {
|
||||
func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (*C, error), tests []ConfigTestData[C]) {
|
||||
for i, test := range tests {
|
||||
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
||||
cfg, err := parser(test.S)
|
||||
@@ -19,9 +19,9 @@ func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (C, err
|
||||
t.Fatalf("%s failed: %v", test.S, err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cfg, test.Cfg) {
|
||||
if !reflect.DeepEqual(*cfg, test.Cfg) {
|
||||
t.Fatalf("input: %s\n wrong config, want:\n %#v\ngot:\n %#v",
|
||||
test.S, test.Cfg, cfg)
|
||||
test.S, test.Cfg, *cfg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
// Suite implements a test suite for restic backends.
|
||||
type Suite[C any] struct {
|
||||
// Config should be used to configure the backend.
|
||||
Config C
|
||||
Config *C
|
||||
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig func() (C, error)
|
||||
NewConfig func() (*C, error)
|
||||
|
||||
// CreateFn is a function that creates a temporary repository for the tests.
|
||||
Create func(cfg C) (restic.Backend, error)
|
||||
@@ -61,7 +61,7 @@ func (s *Suite[C]) RunTests(t *testing.T) {
|
||||
}
|
||||
|
||||
if s.Cleanup != nil {
|
||||
if err = s.Cleanup(s.Config); err != nil {
|
||||
if err = s.Cleanup(*s.Config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -158,13 +158,13 @@ func (s *Suite[C]) RunBenchmarks(b *testing.B) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Cleanup(s.Config); err != nil {
|
||||
if err = s.Cleanup(*s.Config); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Suite[C]) create(t testing.TB) restic.Backend {
|
||||
be, err := s.Create(s.Config)
|
||||
be, err := s.Create(*s.Config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (s *Suite[C]) create(t testing.TB) restic.Backend {
|
||||
}
|
||||
|
||||
func (s *Suite[C]) open(t testing.TB) restic.Backend {
|
||||
be, err := s.Open(s.Config)
|
||||
be, err := s.Open(*s.Config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (s *Suite[C]) TestCreateWithConfig(t *testing.T) {
|
||||
store(t, b, restic.ConfigFile, []byte("test config"))
|
||||
|
||||
// now create the backend again, this must fail
|
||||
_, err = s.Create(s.Config)
|
||||
_, err = s.Create(*s.Config)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error not found for creating a backend with an existing config file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user