From e710dcdff39225631f468976a68fa1dd451ccb2c Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sun, 18 Feb 2018 11:59:32 -0800 Subject: [PATCH] additional integration tests --- Makefile | 2 +- cli/command_block_index_list.go | 5 ++++- tests/end_to_end_test.go | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 156b4d284..298db5167 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ vtest: integration-tests: go build -o $(RELEASE_TMP_DIR)/integration/kopia -ldflags $(LDARGS) github.com/kopia/kopia - KOPIA_EXE=$(RELEASE_TMP_DIR)/integration/kopia go test -timeout 30s github.com/kopia/kopia/tests/... + KOPIA_EXE=$(RELEASE_TMP_DIR)/integration/kopia go test -timeout 30s -v github.com/kopia/kopia/tests/... godoc: godoc -http=:33333 diff --git a/cli/command_block_index_list.go b/cli/command_block_index_list.go index 00015b027..a4093ad2c 100644 --- a/cli/command_block_index_list.go +++ b/cli/command_block_index_list.go @@ -11,6 +11,7 @@ var ( blockIndexListCommand = blockIndexCommands.Command("list", "List block indexes").Alias("ls") blockIndexListAll = blockIndexListCommand.Flag("all", "List all blocks, not just active ones").Short('a').Bool() + blockIndexListSummary = blockIndexListCommand.Flag("summary", "Display block summary").Bool() ) func runListBlockIndexesAction(context *kingpin.ParseContext) error { @@ -34,7 +35,9 @@ func runListBlockIndexesAction(context *kingpin.ParseContext) error { fmt.Printf("%-70v %10v %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormatPrecise)) } - fmt.Printf("total %v blocks\n", len(blks)) + if *blockIndexListSummary { + fmt.Printf("total %v blocks\n", len(blks)) + } return nil } diff --git a/tests/end_to_end_test.go b/tests/end_to_end_test.go index 3994dd179..ffb871fea 100644 --- a/tests/end_to_end_test.go +++ b/tests/end_to_end_test.go @@ -10,8 +10,6 @@ "path/filepath" "strings" "testing" - - "github.com/rs/zerolog/log" ) const repoPassword = "qWQPJ2hiiLgWRRCr" @@ -108,6 +106,17 @@ func TestRepo(t *testing.T) { if got, want := len(sources), 3; got != want { t.Errorf("unexpected number of sources: %v, want %v in %#v", got, want, sources) } + + // expect 5 blocks, each snapshot creation adds one index block. + e.runAndVerifyOutputLineCount(t, 5, "blockindex", "ls") + e.runAndExpectSuccess(t, "blockindex", "optimize") + e.runAndVerifyOutputLineCount(t, 1, "blockindex", "ls") + e.runAndVerifyOutputLineCount(t, 6, "blockindex", "ls", "--all") + + e.runAndExpectSuccess(t, "snapshot", "create", ".", dir1, dir2) + e.runAndVerifyOutputLineCount(t, 2, "blockindex", "ls") + + //t.Fail() } func (e *testenv) runAndExpectSuccess(t *testing.T, args ...string) []string { @@ -118,6 +127,14 @@ func (e *testenv) runAndExpectSuccess(t *testing.T, args ...string) []string { return stdout } +func (e *testenv) runAndVerifyOutputLineCount(t *testing.T, wantLines int, args ...string) []string { + lines := e.runAndExpectSuccess(t, args...) + if len(lines) != wantLines { + t.Errorf("unexpected list of results of 'kopia %v': %v (%v lines), wanted %v", strings.Join(args, " "), lines, len(lines), wantLines) + } + return lines +} + func (e *testenv) run(t *testing.T, args ...string) ([]string, error) { t.Logf("running 'kopia %v'", strings.Join(args, " ")) cmdArgs := append(append([]string(nil), e.fixedArgs...), args...) @@ -134,7 +151,6 @@ func listSnapshotsAndExpectSuccess(t *testing.T, e *testenv, targets ...string) } func createDirectory(dirname string, depth int) error { - log.Printf("createDirectory(%q,%v)", dirname, depth) if err := os.MkdirAll(dirname, 0700); err != nil { return err } @@ -224,7 +240,8 @@ func mustParseSourceInfo(t *testing.T, l string) sourceInfo { } func splitLines(s string) []string { - if strings.TrimSpace(s) == "" { + s = strings.TrimSpace(s) + if s == "" { return nil }