mirror of
https://github.com/restic/restic.git
synced 2025-03-09 00:00:02 +01:00
restic check - add integration tests
cmd_check.go - minor changes: changes error meesage to New instead of Fatal added a short description in the help text. cmd_check_integration_test.go: added two tests which should both fail: invalid input
This commit is contained in:
parent
b5c371892b
commit
2707cb416e
2 changed files with 39 additions and 1 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue