test

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 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

func ParseConfigTester added in v0.16.0

func ParseConfigTester[C comparable](t *testing.T, parser func(s string) (*C, error), tests []ConfigTestData[C])

Types

type ConfigTestData added in v0.16.0

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, restic.Backend, error) error
}

Suite implements a test suite for restic backends.

func (*Suite[C]) BenchmarkLoadFile

func (s *Suite[C]) BenchmarkLoadFile(t *testing.B)

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

func (*Suite[C]) BenchmarkLoadPartialFile

func (s *Suite[C]) 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[C]) BenchmarkLoadPartialFileOffset

func (s *Suite[C]) 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[C]) BenchmarkSave

func (s *Suite[C]) BenchmarkSave(t *testing.B)

BenchmarkSave benchmarks the Save() method of a backend.

func (*Suite[C]) RunBenchmarks

func (s *Suite[C]) RunBenchmarks(b *testing.B)

RunBenchmarks executes all defined benchmarks as subtests of b.

func (*Suite[C]) RunTests

func (s *Suite[C]) RunTests(t *testing.T)

RunTests executes all defined tests as subtests of t.

func (*Suite[C]) TestBackend

func (s *Suite[C]) TestBackend(t *testing.T)

TestBackend tests all functions of the backend.

func (*Suite[C]) TestConfig

func (s *Suite[C]) TestConfig(t *testing.T)

TestConfig saves and loads a config from the backend.

func (*Suite[C]) TestCreateWithConfig

func (s *Suite[C]) TestCreateWithConfig(t *testing.T)

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

func (*Suite[C]) TestList added in v0.7.3

func (s *Suite[C]) TestList(t *testing.T)

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

func (*Suite[C]) TestListCancel added in v0.8.2

func (s *Suite[C]) TestListCancel(t *testing.T)

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

func (*Suite[C]) TestLoad

func (s *Suite[C]) TestLoad(t *testing.T)

TestLoad tests the backend's Load function.

func (*Suite[C]) TestLocation

func (s *Suite[C]) TestLocation(t *testing.T)

TestLocation tests that a location string is returned.

func (*Suite[C]) TestSave

func (s *Suite[C]) TestSave(t *testing.T)

TestSave tests saving data in the backend.

func (*Suite[C]) TestSaveError added in v0.12.0

func (s *Suite[C]) TestSaveError(t *testing.T)

TestSaveError tests saving data in the backend.

func (*Suite[C]) TestSaveWrongHash added in v0.13.0

func (s *Suite[C]) TestSaveWrongHash(t *testing.T)

TestSaveWrongHash tests that uploads with a wrong hash fail

func (*Suite[C]) TestStripPasswordCall added in v0.16.0

func (s *Suite[C]) TestStripPasswordCall(_ *testing.T)

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 added in v0.8.0

func (s *Suite[C]) 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