From 8f811642c3daa76bb67d45683749557c8e70bf55 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 31 Mar 2020 19:09:01 +0200 Subject: [PATCH] Add support for integration tests to wrap the backend --- cmd/restic/global.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 10334b3e7..d3b264b3d 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -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