2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 01:57:10 +00:00
restic/internal/backend/mem/mem_backend_test.go
Michael Eischer f903db492c 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.
2023-06-07 22:31:15 +02:00

66 lines
1.5 KiB
Go

package mem_test
import (
"context"
"testing"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/backend/mem"
"github.com/restic/restic/internal/backend/test"
)
type memConfig struct {
be restic.Backend
}
func newTestSuite() *test.Suite[*memConfig] {
return &test.Suite[*memConfig]{
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (**memConfig, error) {
cfg := &memConfig{}
return &cfg, nil
},
// CreateFn is a function that creates a temporary repository for the tests.
Create: func(cfg *memConfig) (restic.Backend, error) {
if cfg.be != nil {
_, err := cfg.be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
if err != nil && !cfg.be.IsNotExist(err) {
return nil, err
}
if err == nil {
return nil, errors.New("config already exists")
}
}
cfg.be = mem.New()
return cfg.be, nil
},
// OpenFn is a function that opens a previously created temporary repository.
Open: func(cfg *memConfig) (restic.Backend, error) {
if cfg.be == nil {
cfg.be = mem.New()
}
return cfg.be, nil
},
// CleanupFn removes data created during the tests.
Cleanup: func(cfg *memConfig) error {
// no cleanup needed
return nil
},
}
}
func TestSuiteBackendMem(t *testing.T) {
newTestSuite().RunTests(t)
}
func BenchmarkSuiteBackendMem(t *testing.B) {
newTestSuite().RunBenchmarks(t)
}