diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index b5d971f06..629e25ffe 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -35,6 +35,9 @@ finds. It can also be used to read all data and therefore simulate a restore. By default, the "check" command will always load all data directly from the repository and not use a local cache. +The "check" command can now check packfiles for specific snapshots. The snapshots +are filtered via the standard SnapshotFilter. + EXIT STATUS =========== @@ -265,7 +268,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args return summary, err } if len(selectedTrees) == 0 { - return summary, errors.Fatal("snapshotfilter active but no snapshot selected.") + return summary, errors.New("snapshotfilter active but no snapshot selected") } } diff --git a/cmd/restic/cmd_check_integration_test.go b/cmd/restic/cmd_check_integration_test.go index f5a3dc395..1f4104466 100644 --- a/cmd/restic/cmd_check_integration_test.go +++ b/cmd/restic/cmd_check_integration_test.go @@ -5,6 +5,7 @@ import ( "context" "testing" + "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/ui/termstatus" ) @@ -37,3 +38,37 @@ func testRunCheckOutput(gopts GlobalOptions, checkUnused bool) (string, error) { }) return buf.String(), err } + +func testRunCheckOutputWithArgs(gopts GlobalOptions, opts CheckOptions, args []string) (string, error) { + buf := bytes.NewBuffer(nil) + gopts.stdout = buf + err := withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + _, err := runCheck(context.TODO(), opts, gopts, args, term) + return err + }) + return buf.String(), err +} + +func TestRunCheckWrongArgs1(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + testSetupBackupData(t, env) + + _, err := testRunCheckOutputWithArgs(env.gopts, CheckOptions{}, []string{"blubber"}) + rtest.Assert(t, err != nil && err.Error() != "", + // blubber gets quoted - the error string looks messy + "expected specific error message - got %q", err) +} + +func TestRunCheckWrongArgs2(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + testSetupBackupData(t, env) + + opts := CheckOptions{ + SnapshotFilter: restic.SnapshotFilter{Hosts: []string{""}}, + } + _, err := testRunCheckOutputWithArgs(env.gopts, opts, []string{}) + rtest.Assert(t, err != nil && err.Error() == "snapshotfilter active but no snapshot selected", + "expected specific error message - got %q", err) +}