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{}) (restic.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 ¶
- type Suite
- func (s *Suite) BenchmarkLoadFile(t *testing.B)
- func (s *Suite) BenchmarkLoadPartialFile(t *testing.B)
- func (s *Suite) BenchmarkLoadPartialFileOffset(t *testing.B)
- func (s *Suite) BenchmarkSave(t *testing.B)
- func (s *Suite) RunBenchmarks(b *testing.B)
- func (s *Suite) RunTests(t *testing.T)
- func (s *Suite) TestBackend(t *testing.T)
- func (s *Suite) TestConfig(t *testing.T)
- func (s *Suite) TestCreateWithConfig(t *testing.T)
- func (s *Suite) TestDelete(t *testing.T)
- func (s *Suite) TestList(t *testing.T)
- func (s *Suite) TestLoad(t *testing.T)
- func (s *Suite) TestLocation(t *testing.T)
- func (s *Suite) TestSave(t *testing.T)
- func (s *Suite) TestSaveFilenames(t *testing.T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Suite ¶
type Suite struct { // Config should be used to configure the backend. Config interface{} // NewConfig returns a config for a new temporary backend that will be used in tests. NewConfig func() (interface{}, error) // CreateFn is a function that creates a temporary repository for the tests. Create func(cfg interface{}) (restic.Backend, error) // OpenFn is a function that opens a previously created temporary repository. Open func(cfg interface{}) (restic.Backend, error) // CleanupFn removes data created during the tests. Cleanup func(cfg interface{}) error // 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, restic.Backend, error) error }
Suite implements a test suite for restic backends.
func (*Suite) BenchmarkLoadFile ¶
BenchmarkLoadFile benchmarks the Load() method of a backend by loading a complete file.
func (*Suite) BenchmarkLoadPartialFile ¶
BenchmarkLoadPartialFile benchmarks the Load() method of a backend by loading the remainder of a file starting at a given offset.
func (*Suite) 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) BenchmarkSave ¶
BenchmarkSave benchmarks the Save() method of a backend.
func (*Suite) RunBenchmarks ¶
RunBenchmarks executes all defined benchmarks as subtests of b.
func (*Suite) TestBackend ¶
TestBackend tests all functions of the backend.
func (*Suite) TestConfig ¶
TestConfig saves and loads a config from the backend.
func (*Suite) TestCreateWithConfig ¶
TestCreateWithConfig tests that creating a backend in a location which already has a config file fails.
func (*Suite) TestDelete ¶
TestDelete tests the Delete function.
func (*Suite) TestList ¶ added in v0.7.3
TestList makes sure that the backend implements List() pagination correctly.
func (*Suite) TestLocation ¶
TestLocation tests that a location string is returned.
func (*Suite) TestSaveFilenames ¶
TestSaveFilenames tests saving data with various file names in the backend.