Add support for integration tests to wrap the backend

This commit is contained in:
Michael Eischer 2020-03-31 19:09:01 +02:00
parent f4b9544ab2
commit 8f811642c3
1 changed files with 12 additions and 0 deletions

View File

@ -44,6 +44,8 @@ var version = "0.9.6-dev (compiled manually)"
// TimeFormat is the format used for all timestamps printed by restic.
const TimeFormat = "2006-01-02 15:04:05"
type backendWrapper func(r restic.Backend) (restic.Backend, error)
// GlobalOptions hold all global options for restic.
type GlobalOptions struct {
Repo string
@ -68,6 +70,8 @@ type GlobalOptions struct {
stdout io.Writer
stderr io.Writer
backendTestHook backendWrapper
// verbosity is set as follows:
// 0 means: don't print any messages except errors, this is used when --quiet is specified
// 1 is the default: print essential messages
@ -395,6 +399,14 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) {
Warnf("%v returned error, retrying after %v: %v\n", msg, d, err)
})
// wrap backend if a test specified a hook
if opts.backendTestHook != nil {
be, err = opts.backendTestHook(be)
if err != nil {
return nil, err
}
}
s := repository.New(be)
passwordTriesLeft := 1