mirror of
https://github.com/restic/restic.git
synced 2025-12-14 12:01:49 +00:00
drop unused stderr from GlobalOptions
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts BackupOptions, gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
t.Logf("backing up %v in %v", target, dir)
|
||||
if dir != "" {
|
||||
cleanup := rtest.Chdir(t, dir)
|
||||
@@ -261,8 +260,6 @@ func TestBackupNonExistingFile(t *testing.T) {
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
|
||||
env.gopts.stderr = io.Discard
|
||||
|
||||
p := filepath.Join(env.testdata, "0", "0", "9")
|
||||
dirs := []string{
|
||||
filepath.Join(p, "0"),
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func testRunCheck(t testing.TB, gopts GlobalOptions) {
|
||||
t.Helper()
|
||||
output, err := testRunCheckOutput(gopts, true)
|
||||
output, err := testRunCheckOutput(t, gopts, true)
|
||||
if err != nil {
|
||||
t.Error(output)
|
||||
t.Fatalf("unexpected error: %+v", err)
|
||||
@@ -18,13 +18,13 @@ func testRunCheck(t testing.TB, gopts GlobalOptions) {
|
||||
|
||||
func testRunCheckMustFail(t testing.TB, gopts GlobalOptions) {
|
||||
t.Helper()
|
||||
_, err := testRunCheckOutput(gopts, false)
|
||||
_, err := testRunCheckOutput(t, gopts, false)
|
||||
rtest.Assert(t, err != nil, "expected non nil error after check of damaged repository")
|
||||
}
|
||||
|
||||
func testRunCheckOutput(gopts GlobalOptions, checkUnused bool) (string, error) {
|
||||
func testRunCheckOutput(t testing.TB, gopts GlobalOptions, checkUnused bool) (string, error) {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
opts := CheckOptions{
|
||||
ReadData: true,
|
||||
CheckUnused: checkUnused,
|
||||
|
||||
@@ -22,7 +22,7 @@ func testRunCopy(t testing.TB, srcGopts GlobalOptions, dstGopts GlobalOptions) {
|
||||
},
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runCopy(context.TODO(), copyOpts, gopts, nil, gopts.term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ import (
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
||||
func testRunDiffOutput(t testing.TB, gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
opts := DiffOptions{
|
||||
ShowMetadata: false,
|
||||
}
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runDiff(ctx, opts, gopts, []string{firstSnapshotID, secondSnapshotID}, gopts.term)
|
||||
})
|
||||
})
|
||||
@@ -125,10 +125,10 @@ func TestDiff(t *testing.T) {
|
||||
|
||||
// quiet suppresses the diff output except for the summary
|
||||
env.gopts.Quiet = false
|
||||
_, err := testRunDiffOutput(env.gopts, "", secondSnapshotID)
|
||||
_, err := testRunDiffOutput(t, env.gopts, "", secondSnapshotID)
|
||||
rtest.Assert(t, err != nil, "expected error on invalid snapshot id")
|
||||
|
||||
out, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
out, err := testRunDiffOutput(t, env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, pattern := range diffOutputRegexPatterns {
|
||||
@@ -139,7 +139,7 @@ func TestDiff(t *testing.T) {
|
||||
|
||||
// check quiet output
|
||||
env.gopts.Quiet = true
|
||||
outQuiet, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
outQuiet, err := testRunDiffOutput(t, env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.Assert(t, len(outQuiet) < len(out), "expected shorter output on quiet mode %v vs. %v", len(outQuiet), len(out))
|
||||
@@ -156,7 +156,7 @@ func TestDiffJSON(t *testing.T) {
|
||||
// quiet suppresses the diff output except for the summary
|
||||
env.gopts.Quiet = false
|
||||
env.gopts.JSON = true
|
||||
out, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
out, err := testRunDiffOutput(t, env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
rtest.OK(t, err)
|
||||
|
||||
var stat DiffStatsContainer
|
||||
@@ -183,7 +183,7 @@ func TestDiffJSON(t *testing.T) {
|
||||
|
||||
// check quiet output
|
||||
env.gopts.Quiet = true
|
||||
outQuiet, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
outQuiet, err := testRunDiffOutput(t, env.gopts, firstSnapshotID, secondSnapshotID)
|
||||
rtest.OK(t, err)
|
||||
|
||||
stat = DiffStatsContainer{}
|
||||
|
||||
@@ -14,7 +14,7 @@ func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts GlobalOpti
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
gopts.JSON = wantJSON
|
||||
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runFind(ctx, opts, gopts, []string{pattern}, gopts.term)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func testRunForgetMayFail(gopts GlobalOptions, opts ForgetOptions, args ...string) error {
|
||||
func testRunForgetMayFail(t testing.TB, gopts GlobalOptions, opts ForgetOptions, args ...string) error {
|
||||
pruneOpts := PruneOptions{
|
||||
MaxUnused: "5%",
|
||||
}
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.term, args)
|
||||
})
|
||||
}
|
||||
|
||||
func testRunForget(t testing.TB, gopts GlobalOptions, opts ForgetOptions, args ...string) {
|
||||
rtest.OK(t, testRunForgetMayFail(gopts, opts, args...))
|
||||
rtest.OK(t, testRunForgetMayFail(t, gopts, opts, args...))
|
||||
}
|
||||
|
||||
func TestRunForgetSafetyNet(t *testing.T) {
|
||||
@@ -37,20 +37,20 @@ func TestRunForgetSafetyNet(t *testing.T) {
|
||||
testListSnapshots(t, env.gopts, 2)
|
||||
|
||||
// --keep-tags invalid
|
||||
err := testRunForgetMayFail(env.gopts, ForgetOptions{
|
||||
err := testRunForgetMayFail(t, env.gopts, ForgetOptions{
|
||||
KeepTags: restic.TagLists{restic.TagList{"invalid"}},
|
||||
GroupBy: restic.SnapshotGroupByOptions{Host: true, Path: true},
|
||||
})
|
||||
rtest.Assert(t, strings.Contains(err.Error(), `refusing to delete last snapshot of snapshot group "host example, path`), "wrong error message got %v", err)
|
||||
|
||||
// disallow `forget --unsafe-allow-remove-all`
|
||||
err = testRunForgetMayFail(env.gopts, ForgetOptions{
|
||||
err = testRunForgetMayFail(t, env.gopts, ForgetOptions{
|
||||
UnsafeAllowRemoveAll: true,
|
||||
})
|
||||
rtest.Assert(t, strings.Contains(err.Error(), `--unsafe-allow-remove-all is not allowed unless a snapshot filter option is specified`), "wrong error message got %v", err)
|
||||
|
||||
// disallow `forget` without options
|
||||
err = testRunForgetMayFail(env.gopts, ForgetOptions{})
|
||||
err = testRunForgetMayFail(t, env.gopts, ForgetOptions{})
|
||||
rtest.Assert(t, strings.Contains(err.Error(), `no policy was specified, no snapshots will be removed`), "wrong error message got %v", err)
|
||||
|
||||
// `forget --host example --unsafe-allow-remove-all` should work
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func testRunGenerate(gopts GlobalOptions, opts generateOptions) ([]byte, error) {
|
||||
func testRunGenerate(t testing.TB, gopts GlobalOptions, opts generateOptions) ([]byte, error) {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runGenerate(opts, gopts, []string{}, gopts.term)
|
||||
})
|
||||
})
|
||||
@@ -30,14 +30,14 @@ func TestGenerateStdout(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
output, err := testRunGenerate(GlobalOptions{}, tc.opts)
|
||||
output, err := testRunGenerate(t, GlobalOptions{}, tc.opts)
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, strings.Contains(string(output), "# "+tc.name+" completion for restic"), "has no expected completion header")
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Generate shell completions to stdout for two shells", func(t *testing.T) {
|
||||
_, err := testRunGenerate(GlobalOptions{}, generateOptions{BashCompletionFile: "-", FishCompletionFile: "-"})
|
||||
_, err := testRunGenerate(t, GlobalOptions{}, generateOptions{BashCompletionFile: "-", FishCompletionFile: "-"})
|
||||
rtest.Assert(t, err != nil, "generate shell completions to stdout for two shells fails")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func testRunInit(t testing.TB, gopts GlobalOptions) {
|
||||
restic.TestDisableCheckPolynomial(t)
|
||||
restic.TestSetLockTimeout(t, 0)
|
||||
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, InitOptions{}, gopts, nil, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -43,26 +43,26 @@ func TestInitCopyChunkerParams(t *testing.T) {
|
||||
password: env2.gopts.password,
|
||||
},
|
||||
}
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.term)
|
||||
})
|
||||
rtest.Assert(t, err != nil, "expected invalid init options to fail")
|
||||
|
||||
initOpts.CopyChunkerParameters = true
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
var repo *repository.Repository
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
repo, err = OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
||||
return err
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
var otherRepo *repository.Repository
|
||||
err = withTermStatus(env2.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env2.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
otherRepo, err = OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
})
|
||||
})
|
||||
@@ -42,7 +42,7 @@ func testRunKeyAddNewKey(t testing.TB, newPassword string, gopts GlobalOptions)
|
||||
testKeyNewPassword = ""
|
||||
}()
|
||||
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -55,7 +55,7 @@ func testRunKeyAddNewKeyUserHost(t testing.TB, gopts GlobalOptions) {
|
||||
}()
|
||||
|
||||
t.Log("adding key for john@example.com")
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
Username: "john",
|
||||
Hostname: "example.com",
|
||||
@@ -63,7 +63,7 @@ func testRunKeyAddNewKeyUserHost(t testing.TB, gopts GlobalOptions) {
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
_ = withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
repo, err := OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
||||
rtest.OK(t, err)
|
||||
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 2, "")
|
||||
@@ -81,7 +81,7 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
|
||||
testKeyNewPassword = ""
|
||||
}()
|
||||
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -90,7 +90,7 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
|
||||
func testRunKeyRemove(t testing.TB, gopts GlobalOptions, IDs []string) {
|
||||
t.Logf("remove %d keys: %q\n", len(IDs), IDs)
|
||||
for _, id := range IDs {
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{id}, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -123,7 +123,7 @@ func TestKeyAddRemove(t *testing.T) {
|
||||
|
||||
env.gopts.password = passwordList[len(passwordList)-1]
|
||||
t.Logf("testing access with last password %q\n", env.gopts.password)
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -137,7 +137,7 @@ func TestKeyAddInvalid(t *testing.T) {
|
||||
defer cleanup()
|
||||
testRunInit(t, env.gopts)
|
||||
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
NewPasswordFile: "some-file",
|
||||
InsecureNoPassword: true,
|
||||
@@ -148,7 +148,7 @@ func TestKeyAddInvalid(t *testing.T) {
|
||||
pwfile := filepath.Join(t.TempDir(), "pwfile")
|
||||
rtest.OK(t, os.WriteFile(pwfile, []byte{}, 0o666))
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
NewPasswordFile: pwfile,
|
||||
}, []string{}, gopts.term)
|
||||
@@ -163,7 +163,7 @@ func TestKeyAddEmpty(t *testing.T) {
|
||||
defer cleanup()
|
||||
testRunInit(t, env.gopts)
|
||||
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
InsecureNoPassword: true,
|
||||
}, []string{}, gopts.term)
|
||||
@@ -198,20 +198,20 @@ func TestKeyProblems(t *testing.T) {
|
||||
testKeyNewPassword = ""
|
||||
}()
|
||||
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil, "expected passwd change to fail")
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil, "expected key adding to fail")
|
||||
|
||||
t.Logf("testing access with initial password %q\n", env.gopts.password)
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
@@ -227,31 +227,31 @@ func TestKeyCommandInvalidArguments(t *testing.T) {
|
||||
return &emptySaveBackend{r}, nil
|
||||
}
|
||||
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{"johndoe"}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key add: %v", err)
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{"johndoe"}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key passwd: %v", err)
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{"johndoe"}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key list: %v", err)
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "one argument"), "unexpected error for key remove: %v", err)
|
||||
|
||||
err = withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{"john", "doe"}, gopts.term)
|
||||
})
|
||||
t.Log(err)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func testRunList(t testing.TB, gopts GlobalOptions, tpe string) restic.IDs {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runList(ctx, gopts, []string{tpe}, gopts.term)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func testRunLsWithOpts(t testing.TB, gopts GlobalOptions, opts LsOptions, args []string) []byte {
|
||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
||||
gopts.Quiet = true
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runLs(context.TODO(), opts, gopts, args, gopts.term)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -62,7 +62,7 @@ func testRunMount(t testing.TB, gopts GlobalOptions, dir string, wg *sync.WaitGr
|
||||
opts := MountOptions{
|
||||
TimeTemplate: time.RFC3339,
|
||||
}
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runMount(context.TODO(), opts, gopts, []string{dir}, gopts.term)
|
||||
}))
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func checkSnapshots(t testing.TB, gopts GlobalOptions, mountpoint string, snapsh
|
||||
}
|
||||
}
|
||||
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
_, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,22 +13,22 @@ import (
|
||||
|
||||
func testRunPrune(t testing.TB, gopts GlobalOptions, opts PruneOptions) {
|
||||
t.Helper()
|
||||
rtest.OK(t, testRunPruneOutput(gopts, opts))
|
||||
rtest.OK(t, testRunPruneOutput(t, gopts, opts))
|
||||
}
|
||||
|
||||
func testRunPruneMustFail(t testing.TB, gopts GlobalOptions, opts PruneOptions) {
|
||||
t.Helper()
|
||||
err := testRunPruneOutput(gopts, opts)
|
||||
err := testRunPruneOutput(t, gopts, opts)
|
||||
rtest.Assert(t, err != nil, "expected non nil error")
|
||||
}
|
||||
|
||||
func testRunPruneOutput(gopts GlobalOptions, opts PruneOptions) error {
|
||||
func testRunPruneOutput(t testing.TB, gopts GlobalOptions, opts PruneOptions) error {
|
||||
oldHook := gopts.backendTestHook
|
||||
gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
|
||||
defer func() {
|
||||
gopts.backendTestHook = oldHook
|
||||
}()
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), opts, gopts, gopts.term)
|
||||
})
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func testRunForgetJSON(t testing.TB, gopts GlobalOptions, args ...string) {
|
||||
pruneOpts := PruneOptions{
|
||||
MaxUnused: "5%",
|
||||
}
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.term, args)
|
||||
})
|
||||
})
|
||||
@@ -121,7 +121,7 @@ func testPrune(t *testing.T, pruneOpts PruneOptions, checkOpts CheckOptions) {
|
||||
|
||||
createPrunableRepo(t, env)
|
||||
testRunPrune(t, env.gopts, pruneOpts)
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.term)
|
||||
return err
|
||||
}))
|
||||
@@ -157,7 +157,7 @@ func TestPruneWithDamagedRepository(t *testing.T) {
|
||||
env.gopts.backendTestHook = oldHook
|
||||
}()
|
||||
// prune should fail
|
||||
rtest.Equals(t, repository.ErrPacksMissing, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.Equals(t, repository.ErrPacksMissing, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), pruneDefaultOptions, gopts, gopts.term)
|
||||
}), "prune should have reported index not complete error")
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o
|
||||
if checkOK {
|
||||
testRunCheck(t, env.gopts)
|
||||
} else {
|
||||
rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.Assert(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), optionsCheck, gopts, nil, gopts.term)
|
||||
return err
|
||||
}) != nil,
|
||||
@@ -241,7 +241,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o
|
||||
testRunPrune(t, env.gopts, optionsPrune)
|
||||
testRunCheck(t, env.gopts)
|
||||
} else {
|
||||
rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.Assert(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), optionsPrune, gopts, gopts.term)
|
||||
}) != nil,
|
||||
"prune should have reported an error")
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func testRunRecover(t testing.TB, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRecover(context.TODO(), gopts, gopts.term)
|
||||
}))
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func TestRecover(t *testing.T) {
|
||||
ids = testListSnapshots(t, env.gopts, 1)
|
||||
testRunCheck(t, env.gopts)
|
||||
// check that the root tree is included in the snapshot
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runCat(context.TODO(), gopts, []string{"tree", ids[0].String() + ":" + sn.Tree.Str()}, gopts.term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.stdout = io.Discard
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
}))
|
||||
@@ -29,7 +29,7 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
||||
datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz")
|
||||
rtest.SetupTarTestFixture(t, env.base, datafile)
|
||||
|
||||
out, err := testRunCheckOutput(env.gopts, false)
|
||||
out, err := testRunCheckOutput(t, env.gopts, false)
|
||||
if !strings.Contains(out, "contained in several indexes") {
|
||||
t.Fatalf("did not find checker hint for packs in several indexes")
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
|
||||
env.gopts.backendTestHook = nil
|
||||
out, err = testRunCheckOutput(env.gopts, false)
|
||||
out, err = testRunCheckOutput(t, env.gopts, false)
|
||||
if len(out) != 0 {
|
||||
t.Fatalf("expected no output from the checker, got: %v", out)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func TestRebuildIndexFailsOnAppendOnly(t *testing.T) {
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return &appendOnlyBackend{r}, nil
|
||||
}
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.stdout = io.Discard
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@ func testRunRepairSnapshot(t testing.TB, gopts GlobalOptions, forget bool) {
|
||||
Forget: forget,
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRepairSnapshots(context.TODO(), gopts, opts, nil, gopts.term)
|
||||
}))
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func TestRepairSnapshotsWithLostData(t *testing.T) {
|
||||
// repository must be ok after removing the broken snapshots
|
||||
testRunForget(t, env.gopts, ForgetOptions{}, snapshotIDs[0].String(), snapshotIDs[1].String())
|
||||
testListSnapshots(t, env.gopts, 2)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
_, err := testRunCheckOutput(t, env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func TestRepairSnapshotsWithLostTree(t *testing.T) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
testRunRepairSnapshot(t, env.gopts, true)
|
||||
testListSnapshots(t, env.gopts, 1)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
_, err := testRunCheckOutput(t, env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestRepairSnapshotsWithLostRootTree(t *testing.T) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
testRunRepairSnapshot(t, env.gopts, true)
|
||||
testListSnapshots(t, env.gopts, 0)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
_, err := testRunCheckOutput(t, env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -26,11 +25,11 @@ func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snaps
|
||||
}
|
||||
opts.Excludes = excludes
|
||||
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(snapshotID, opts, gopts))
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(t, snapshotID, opts, gopts))
|
||||
}
|
||||
|
||||
func testRunRestoreAssumeFailure(snapshotID string, opts RestoreOptions, gopts GlobalOptions) error {
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
func testRunRestoreAssumeFailure(t testing.TB, snapshotID string, opts RestoreOptions, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRestore(ctx, opts, gopts, gopts.term, []string{snapshotID})
|
||||
})
|
||||
}
|
||||
@@ -44,7 +43,7 @@ func testRunRestoreLatest(t testing.TB, gopts GlobalOptions, dir string, paths [
|
||||
},
|
||||
}
|
||||
|
||||
rtest.OK(t, testRunRestoreAssumeFailure("latest", opts, gopts))
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(t, "latest", opts, gopts))
|
||||
}
|
||||
|
||||
func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, includes []string) {
|
||||
@@ -53,7 +52,7 @@ func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snaps
|
||||
}
|
||||
opts.Includes = includes
|
||||
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(snapshotID.String(), opts, gopts))
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(t, snapshotID.String(), opts, gopts))
|
||||
}
|
||||
|
||||
func testRunRestoreIncludesFromFile(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, includesFile string) {
|
||||
@@ -62,7 +61,7 @@ func testRunRestoreIncludesFromFile(t testing.TB, gopts GlobalOptions, dir strin
|
||||
}
|
||||
opts.IncludeFiles = []string{includesFile}
|
||||
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(snapshotID.String(), opts, gopts))
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(t, snapshotID.String(), opts, gopts))
|
||||
}
|
||||
|
||||
func testRunRestoreExcludesFromFile(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, excludesFile string) {
|
||||
@@ -71,7 +70,7 @@ func testRunRestoreExcludesFromFile(t testing.TB, gopts GlobalOptions, dir strin
|
||||
}
|
||||
opts.ExcludeFiles = []string{excludesFile}
|
||||
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(snapshotID.String(), opts, gopts))
|
||||
rtest.OK(t, testRunRestoreAssumeFailure(t, snapshotID.String(), opts, gopts))
|
||||
}
|
||||
|
||||
func TestRestoreMustFailWhenUsingBothIncludesAndExcludes(t *testing.T) {
|
||||
@@ -92,7 +91,7 @@ func TestRestoreMustFailWhenUsingBothIncludesAndExcludes(t *testing.T) {
|
||||
restoreOpts.Includes = includePatterns
|
||||
restoreOpts.Excludes = excludePatterns
|
||||
|
||||
err := testRunRestoreAssumeFailure("latest", restoreOpts, env.gopts)
|
||||
err := testRunRestoreAssumeFailure(t, "latest", restoreOpts, env.gopts)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "exclude and include patterns are mutually exclusive"),
|
||||
"expected: %s error, got %v", "exclude and include patterns are mutually exclusive", err)
|
||||
}
|
||||
@@ -336,7 +335,6 @@ func TestRestoreWithPermissionFailure(t *testing.T) {
|
||||
|
||||
snapshots := testListSnapshots(t, env.gopts, 1)
|
||||
|
||||
env.gopts.stderr = io.Discard
|
||||
testRunRestore(t, env.gopts, filepath.Join(env.base, "restore"), snapshots[0].String())
|
||||
|
||||
// make sure that all files have been restored, regardless of any
|
||||
|
||||
@@ -20,7 +20,7 @@ func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string,
|
||||
Metadata: metadata,
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), opts, gopts, nil, gopts.term)
|
||||
}))
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func getSnapshot(t testing.TB, snapshotID restic.ID, env *testEnvironment) *rest
|
||||
t.Helper()
|
||||
|
||||
var snapshots []*restic.Snapshot
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -117,7 +117,7 @@ func testRewriteMetadata(t *testing.T, metadata snapshotMetadataArgs) {
|
||||
testRunRewriteExclude(t, env.gopts, []string{}, true, metadata)
|
||||
|
||||
var snapshots []*restic.Snapshot
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -157,7 +157,7 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
||||
defer cleanup()
|
||||
createBasicRewriteRepo(t, env)
|
||||
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.term)
|
||||
}))
|
||||
// no new snapshot should be created as the snapshot already has a summary
|
||||
@@ -165,7 +165,7 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
||||
|
||||
// replace snapshot by one without a summary
|
||||
var oldSummary *restic.SnapshotSummary
|
||||
err := withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
_, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -182,7 +182,7 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
|
||||
// rewrite snapshot and lookup ID of new snapshot
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.term)
|
||||
}))
|
||||
newSnapshots := testListSnapshots(t, env.gopts, 2)
|
||||
|
||||
@@ -14,7 +14,7 @@ func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snap
|
||||
gopts.JSON = true
|
||||
|
||||
opts := SnapshotOptions{}
|
||||
return withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runSnapshots(ctx, opts, gopts, []string{}, gopts.term)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func testRunTag(t testing.TB, opts TagOptions, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runTag(context.TODO(), opts, gopts, gopts.term, []string{})
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ type GlobalOptions struct {
|
||||
|
||||
password string
|
||||
stdout io.Writer
|
||||
stderr io.Writer
|
||||
term ui.Terminal
|
||||
|
||||
backends *location.Registry
|
||||
|
||||
@@ -71,28 +71,28 @@ func TestRestoreFailsWhenUsingInvalidPatterns(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Test --exclude
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{Excludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{Excludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
|
||||
rtest.Equals(t, `Fatal: --exclude: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
// Test --iexclude
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{InsensitiveExcludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{InsensitiveExcludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
|
||||
rtest.Equals(t, `Fatal: --iexclude: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
// Test --include
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
|
||||
rtest.Equals(t, `Fatal: --include: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
// Test --iinclude
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{InsensitiveIncludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{InsensitiveIncludes: []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"}}}, env.gopts)
|
||||
|
||||
rtest.Equals(t, `Fatal: --iinclude: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
@@ -112,22 +112,22 @@ func TestRestoreFailsWhenUsingInvalidPatternsFromFile(t *testing.T) {
|
||||
t.Fatalf("Could not write include file: %v", fileErr)
|
||||
}
|
||||
|
||||
err := testRunRestoreAssumeFailure("latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{IncludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
err := testRunRestoreAssumeFailure(t, "latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{IncludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
rtest.Equals(t, `Fatal: --include-file: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{ExcludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{ExcludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
rtest.Equals(t, `Fatal: --exclude-file: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{InsensitiveIncludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{IncludePatternOptions: filter.IncludePatternOptions{InsensitiveIncludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
rtest.Equals(t, `Fatal: --iinclude-file: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
err = testRunRestoreAssumeFailure("latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{InsensitiveExcludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
err = testRunRestoreAssumeFailure(t, "latest", RestoreOptions{ExcludePatternOptions: filter.ExcludePatternOptions{InsensitiveExcludeFiles: []string{patternsFile}}}, env.gopts)
|
||||
rtest.Equals(t, `Fatal: --iexclude-file: invalid pattern(s) provided:
|
||||
*[._]log[.-][0-9]
|
||||
!*[._]log[.-][0-9]`, err.Error())
|
||||
|
||||
@@ -216,7 +216,6 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
||||
// usually consists of one or multiple lines and therefore can be handled well
|
||||
// by t.Log.
|
||||
stdout: &logOutputter{t},
|
||||
stderr: &logOutputter{t},
|
||||
extended: make(options.Options),
|
||||
|
||||
// replace this hook with "nil" if listing a filetype more than once is necessary
|
||||
@@ -245,7 +244,7 @@ func testSetupBackupData(t testing.TB, env *testEnvironment) string {
|
||||
|
||||
func listPacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
var packs restic.IDSet
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, r, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -264,7 +263,7 @@ func listPacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
|
||||
func listTreePacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
var treePacks restic.IDSet
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, r, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -295,7 +294,7 @@ func captureBackend(gopts *GlobalOptions) func() backend.Backend {
|
||||
|
||||
func removePacks(gopts GlobalOptions, t testing.TB, remove restic.IDSet) {
|
||||
be := captureBackend(&gopts)
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, _, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -311,7 +310,7 @@ func removePacks(gopts GlobalOptions, t testing.TB, remove restic.IDSet) {
|
||||
|
||||
func removePacksExcept(gopts GlobalOptions, t testing.TB, keep restic.IDSet, removeTreePacks bool) {
|
||||
be := captureBackend(&gopts)
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, r, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -372,7 +371,7 @@ func lastSnapshot(old, new map[string]struct{}) (map[string]struct{}, string) {
|
||||
|
||||
func testLoadSnapshot(t testing.TB, gopts GlobalOptions, id restic.ID) *restic.Snapshot {
|
||||
var snapshot *restic.Snapshot
|
||||
err := withTermStatus(gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
_, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
@@ -424,11 +423,11 @@ func withCaptureStdout(gopts GlobalOptions, inner func(gopts GlobalOptions) erro
|
||||
return buf, err
|
||||
}
|
||||
|
||||
func withTermStatus(gopts GlobalOptions, callback func(ctx context.Context, gopts GlobalOptions) error) error {
|
||||
func withTermStatus(t testing.TB, gopts GlobalOptions, callback func(ctx context.Context, gopts GlobalOptions) error) error {
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
var wg sync.WaitGroup
|
||||
|
||||
term := termstatus.New(os.Stdin, gopts.stdout, gopts.stderr, gopts.Quiet)
|
||||
term := termstatus.New(os.Stdin, gopts.stdout, &logOutputter{t: t}, gopts.Quiet)
|
||||
gopts.term = term
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
@@ -87,14 +87,14 @@ func TestListOnce(t *testing.T) {
|
||||
|
||||
createPrunableRepo(t, env)
|
||||
testRunPrune(t, env.gopts, pruneOpts)
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.term)
|
||||
return err
|
||||
}))
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
}))
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, gopts, gopts.term)
|
||||
}))
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func TestFindListOnce(t *testing.T) {
|
||||
thirdSnapshot := restic.NewIDSet(testListSnapshots(t, env.gopts, 3)...)
|
||||
|
||||
var snapshotIDs restic.IDSet
|
||||
rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -174,13 +174,12 @@ func main() {
|
||||
|
||||
globalOptions := GlobalOptions{
|
||||
stdout: os.Stdout,
|
||||
stderr: os.Stderr,
|
||||
backends: collectBackends(),
|
||||
}
|
||||
func() {
|
||||
term, cancel := termstatus.Setup(os.Stdin, os.Stdout, os.Stderr, globalOptions.Quiet)
|
||||
defer cancel()
|
||||
globalOptions.stdout, globalOptions.stderr = termstatus.WrapStdio(term)
|
||||
globalOptions.stdout = termstatus.WrapStdout(term)
|
||||
globalOptions.term = term
|
||||
ctx := createGlobalContext(os.Stderr)
|
||||
err = newRootCommand(&globalOptions).ExecuteContext(ctx)
|
||||
|
||||
Reference in New Issue
Block a user