From c76568877950a2b7d6bb1842508a7c95a04ca184 Mon Sep 17 00:00:00 2001 From: Chapuis Bertil Date: Fri, 28 Aug 2015 19:31:05 +0200 Subject: [PATCH] find command integration tests --- cmd/restic/cmd_find.go | 7 +++---- cmd/restic/integration_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 754d0f52b..fa2d7859e 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -122,11 +122,10 @@ func (c CmdFind) findInSnapshot(repo *repository.Repository, id backend.ID) erro if len(results) == 0 { return nil } - - fmt.Printf("found %d matching entries in snapshot %s\n", len(results), id) + c.global.Verbosef("found %d matching entries in snapshot %s\n", len(results), id) for _, res := range results { res.node.Name = filepath.Join(res.path, res.node.Name) - fmt.Printf(" %s\n", res.node) + c.global.Printf(" %s\n", res.node) } return nil @@ -138,7 +137,7 @@ func (CmdFind) Usage() string { func (c CmdFind) Execute(args []string) error { if len(args) != 1 { - return fmt.Errorf("invalid number of arguments, Usage: %s", c.Usage()) + return fmt.Errorf("wrong number of arguments, Usage: %s", c.Usage()) } var err error diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 68266723b..360adca0f 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -100,6 +100,16 @@ func cmdLs(t testing.TB, global GlobalOptions, snapshotID string) []string { return strings.Split(string(buf.Bytes()), "\n") } +func cmdFind(t testing.TB, global GlobalOptions, pattern string) []string { + var buf bytes.Buffer + global.stdout = &buf + + cmd := &CmdFind{global: &global} + OK(t, cmd.Execute([]string{pattern})) + + return strings.Split(string(buf.Bytes()), "\n") +} + func TestBackup(t *testing.T) { withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { datafile := filepath.Join("testdata", "backup-data.tar.gz") @@ -617,3 +627,22 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) { "meta data of intermediate directory hasn't been restore") }) } + +func TestFind(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { + datafile := filepath.Join("testdata", "backup-data.tar.gz") + cmdInit(t, global) + SetupTarTestFixture(t, env.testdata, datafile) + cmdBackup(t, global, []string{env.testdata}, nil) + cmdCheck(t, global) + + results := cmdFind(t, global, "unexistingfile") + Assert(t, len(results) != 0, "unexisting file found in repo (%v)", datafile) + + results = cmdFind(t, global, "testfile") + Assert(t, len(results) != 1, "file not found in repo (%v)", datafile) + + results = cmdFind(t, global, "test") + Assert(t, len(results) < 2, "less than two file found in repo (%v)", datafile) + }) +}