Documentation
¶
Overview ¶
Package test contains a test suite with benchmarks for restic backends.
Overview ¶
For the test suite to work a few functions need to be implemented to create new config, create a backend, open it and run cleanup tasks afterwards. The Suite struct has fields for each function.
So for a new backend, a Suite needs to be built with callback functions, then the methods RunTests() and RunBenchmarks() can be used to run the individual tests and benchmarks as subtests/subbenchmarks.
Example ¶
Assuming a *Suite is returned by newTestSuite(), the tests and benchmarks can be run like this:
func newTestSuite(t testing.TB) *test.Suite { return &test.Suite{ Create: func(cfg interface{}) (backend.Backend, error) { [...] }, [...] } } func TestSuiteBackendMem(t *testing.T) { newTestSuite(t).RunTests(t) } func BenchmarkSuiteBackendMem(b *testing.B) { newTestSuite(b).RunBenchmarks(b) }
The functions are run in alphabetical order.
Add new tests ¶
A new test or benchmark can be added by implementing a method on *Suite with the name starting with "Test" and a single *testing.T parameter for test. For benchmarks, the name must start with "Benchmark" and the parameter is a *testing.B
Index ¶
- func LoadAll(ctx context.Context, be backend.Backend, h backend.Handle) ([]byte, error)
- func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (*C, error), tests []ConfigTestData[C])
- type ConfigTestData
- type Suite
- func (s *Suite[C]) BenchmarkLoadFile(t *testing.B)
- func (s *Suite[C]) BenchmarkLoadPartialFile(t *testing.B)
- func (s *Suite[C]) BenchmarkLoadPartialFileOffset(t *testing.B)
- func (s *Suite[C]) BenchmarkSave(t *testing.B)
- func (s *Suite[C]) RunBenchmarks(b *testing.B)
- func (s *Suite[C]) RunTests(t *testing.T)
- func (s *Suite[C]) TestBackend(t *testing.T)
- func (s *Suite[C]) TestConfig(t *testing.T)
- func (s *Suite[C]) TestCreateWithConfig(t *testing.T)
- func (s *Suite[C]) TestList(t *testing.T)
- func (s *Suite[C]) TestListCancel(t *testing.T)
- func (s *Suite[C]) TestLoad(t *testing.T)
- func (s *Suite[C]) TestSave(t *testing.T)
- func (s *Suite[C]) TestSaveError(t *testing.T)
- func (s *Suite[C]) TestSaveWrongHash(t *testing.T)
- func (s *Suite[C]) TestStripPasswordCall(_ *testing.T)
- func (s *Suite[C]) TestZZZDelete(t *testing.T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseConfigTester ¶
func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (*C, error), tests []ConfigTestData[C])
Types ¶
type ConfigTestData ¶
type ConfigTestData[C comparable] struct { S string Cfg C }
type Suite ¶
type Suite[C any] struct { // Config should be used to configure the backend. Config *C // NewConfig returns a config for a new temporary backend that will be used in tests. NewConfig func() (*C, error) // Factory contains a factory that can be used to create or open a repository for the tests. Factory location.Factory // MinimalData instructs the tests to not use excessive data. MinimalData bool // WaitForDelayedRemoval is set to a non-zero value to instruct the test // suite to wait for this amount of time until a file that was removed // really disappeared. WaitForDelayedRemoval time.Duration // ErrorHandler allows ignoring certain errors. ErrorHandler func(testing.TB, backend.Backend, error) error }
Suite implements a test suite for restic backends.
func (*Suite[C]) BenchmarkLoadFile ¶
BenchmarkLoadFile benchmarks the Load() method of a backend by loading a complete file.
func (*Suite[C]) BenchmarkLoadPartialFile ¶
BenchmarkLoadPartialFile benchmarks the Load() method of a backend by loading the remainder of a file starting at a given offset.
func (*Suite[C]) BenchmarkLoadPartialFileOffset ¶
BenchmarkLoadPartialFileOffset benchmarks the Load() method of a backend by loading a number of bytes of a file starting at a given offset.
func (*Suite[C]) BenchmarkSave ¶
BenchmarkSave benchmarks the Save() method of a backend.
func (*Suite[C]) RunBenchmarks ¶
RunBenchmarks executes all defined benchmarks as subtests of b.
func (*Suite[C]) TestBackend ¶
TestBackend tests all functions of the backend.
func (*Suite[C]) TestConfig ¶
TestConfig saves and loads a config from the backend.
func (*Suite[C]) TestCreateWithConfig ¶
TestCreateWithConfig tests that creating a backend in a location which already has a config file fails.
func (*Suite[C]) TestList ¶
TestList makes sure that the backend implements List() pagination correctly.
func (*Suite[C]) TestListCancel ¶
TestListCancel tests that the context is respected and the error is returned by List.
func (*Suite[C]) TestSaveError ¶
TestSaveError tests saving data in the backend.
func (*Suite[C]) TestSaveWrongHash ¶
TestSaveWrongHash tests that uploads with a wrong hash fail
func (*Suite[C]) TestStripPasswordCall ¶
TestStripPasswordCall tests that the StripPassword method of a factory can be called without crashing. It does not verify whether passwords are removed correctly
func (*Suite[C]) TestZZZDelete ¶
TestZZZDelete tests the Delete function. The name ensures that this test is executed last.