github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/backend/test/doc.go (about)

     1  // Package test contains a test suite with benchmarks for restic backends.
     2  //
     3  // Overview
     4  //
     5  // For the test suite to work a few functions need to be implemented to create
     6  // new config, create a backend, open it and run cleanup tasks afterwards. The
     7  // Suite struct has fields for each function.
     8  //
     9  // So for a new backend, a Suite needs to be built with callback functions,
    10  // then the methods RunTests() and RunBenchmarks() can be used to run the
    11  // individual tests and benchmarks as subtests/subbenchmarks.
    12  //
    13  // Example
    14  //
    15  // Assuming a *Suite is returned by newTestSuite(), the tests and benchmarks
    16  // can be run like this:
    17  //   func newTestSuite(t testing.TB) *test.Suite {
    18  //   	return &test.Suite{
    19  //   		Create: func(cfg interface{}) (restic.Backend, error) {
    20  //   			[...]
    21  //   		},
    22  //   		[...]
    23  //   	}
    24  //   }
    25  //
    26  //   func TestSuiteBackendMem(t *testing.T) {
    27  //   	newTestSuite(t).RunTests(t)
    28  //   }
    29  //
    30  //   func BenchmarkSuiteBackendMem(b *testing.B) {
    31  //   	newTestSuite(b).RunBenchmarks(b)
    32  //   }
    33  //
    34  // The functions are run in alphabetical order.
    35  //
    36  // Add new tests
    37  //
    38  // A new test or benchmark can be added by implementing a method on *Suite
    39  // with the name starting with "Test" and a single *testing.T parameter for
    40  // test. For benchmarks, the name must start with "Benchmark" and the parameter
    41  // is a *testing.B
    42  package test