test

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2022 License: BSD-2-Clause Imports: 17 Imported by: 0

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

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

func (s *Suite) BenchmarkLoadFile(t *testing.B)

BenchmarkLoadFile benchmarks the Load() method of a backend by loading a complete file.

func (*Suite) BenchmarkLoadPartialFile

func (s *Suite) BenchmarkLoadPartialFile(t *testing.B)

BenchmarkLoadPartialFile benchmarks the Load() method of a backend by loading the remainder of a file starting at a given offset.

func (*Suite) BenchmarkLoadPartialFileOffset

func (s *Suite) BenchmarkLoadPartialFileOffset(t *testing.B)

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

func (s *Suite) BenchmarkSave(t *testing.B)

BenchmarkSave benchmarks the Save() method of a backend.

func (*Suite) RunBenchmarks

func (s *Suite) RunBenchmarks(b *testing.B)

RunBenchmarks executes all defined benchmarks as subtests of b.

func (*Suite) RunTests

func (s *Suite) RunTests(t *testing.T)

RunTests executes all defined tests as subtests of t.

func (*Suite) TestBackend

func (s *Suite) TestBackend(t *testing.T)

TestBackend tests all functions of the backend.

func (*Suite) TestConfig

func (s *Suite) TestConfig(t *testing.T)

TestConfig saves and loads a config from the backend.

func (*Suite) TestCreateWithConfig

func (s *Suite) TestCreateWithConfig(t *testing.T)

TestCreateWithConfig tests that creating a backend in a location which already has a config file fails.

func (*Suite) TestList added in v0.7.3

func (s *Suite) TestList(t *testing.T)

TestList makes sure that the backend implements List() pagination correctly.

func (*Suite) TestListCancel added in v0.8.2

func (s *Suite) TestListCancel(t *testing.T)

TestListCancel tests that the context is respected and the error is returned by List.

func (*Suite) TestLoad

func (s *Suite) TestLoad(t *testing.T)

TestLoad tests the backend's Load function.

func (*Suite) TestLocation

func (s *Suite) TestLocation(t *testing.T)

TestLocation tests that a location string is returned.

func (*Suite) TestSave

func (s *Suite) TestSave(t *testing.T)

TestSave tests saving data in the backend.

func (*Suite) TestSaveError added in v0.12.0

func (s *Suite) TestSaveError(t *testing.T)

TestSaveError tests saving data in the backend.

func (*Suite) TestSaveWrongHash added in v0.13.0

func (s *Suite) TestSaveWrongHash(t *testing.T)

TestSaveWrongHash tests that uploads with a wrong hash fail

func (*Suite) TestZZZDelete added in v0.8.0

func (s *Suite) TestZZZDelete(t *testing.T)

TestZZZDelete tests the Delete function. The name ensures that this test is executed last.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL