mirror of
https://github.com/octoleo/restic.git
synced 2024-11-16 01:57:10 +00:00
test: print log output if testRunCheck fails
This commit is contained in:
parent
419e6f26b1
commit
06fd6b54d7
@ -64,7 +64,7 @@ func TestRepairSnapshotsWithLostData(t *testing.T) {
|
||||
// repository must be ok after removing the broken snapshots
|
||||
testRunForget(t, env.gopts, snapshotIDs[0].String(), snapshotIDs[1].String())
|
||||
testListSnapshots(t, env.gopts, 2)
|
||||
_, err := testRunCheckOutput(env.gopts)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func TestRepairSnapshotsWithLostTree(t *testing.T) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
testRunRepairSnapshot(t, env.gopts, true)
|
||||
testListSnapshots(t, env.gopts, 1)
|
||||
_, err := testRunCheckOutput(env.gopts)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ func TestRepairSnapshotsWithLostRootTree(t *testing.T) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
testRunRepairSnapshot(t, env.gopts, true)
|
||||
testListSnapshots(t, env.gopts, 0)
|
||||
_, err := testRunCheckOutput(env.gopts)
|
||||
_, err := testRunCheckOutput(env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
|
@ -150,14 +150,20 @@ func testRunRestoreAssumeFailure(snapshotID string, opts RestoreOptions, gopts G
|
||||
|
||||
func testRunCheck(t testing.TB, gopts GlobalOptions) {
|
||||
t.Helper()
|
||||
opts := CheckOptions{
|
||||
ReadData: true,
|
||||
CheckUnused: true,
|
||||
output, err := testRunCheckOutput(gopts, true)
|
||||
if err != nil {
|
||||
t.Error(output)
|
||||
t.Fatalf("unexpected error: %+v", err)
|
||||
}
|
||||
rtest.OK(t, runCheck(context.TODO(), opts, gopts, nil))
|
||||
}
|
||||
|
||||
func testRunCheckOutput(gopts GlobalOptions) (string, error) {
|
||||
func testRunCheckMustFail(t testing.TB, gopts GlobalOptions) {
|
||||
t.Helper()
|
||||
_, err := testRunCheckOutput(gopts, false)
|
||||
rtest.Assert(t, err != nil, "expected non nil error after check of damaged repository")
|
||||
}
|
||||
|
||||
func testRunCheckOutput(gopts GlobalOptions, checkUnused bool) (string, error) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
globalOptions.stdout = buf
|
||||
@ -166,18 +172,14 @@ func testRunCheckOutput(gopts GlobalOptions) (string, error) {
|
||||
}()
|
||||
|
||||
opts := CheckOptions{
|
||||
ReadData: true,
|
||||
ReadData: true,
|
||||
CheckUnused: checkUnused,
|
||||
}
|
||||
|
||||
err := runCheck(context.TODO(), opts, gopts, nil)
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
func testRunCheckMustFail(t testing.TB, gopts GlobalOptions) {
|
||||
_, err := testRunCheckOutput(gopts)
|
||||
rtest.Assert(t, err != nil, "expected non nil error after check of damaged repository")
|
||||
}
|
||||
|
||||
func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
@ -1488,7 +1490,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)
|
||||
out, err := testRunCheckOutput(env.gopts, false)
|
||||
if !strings.Contains(out, "contained in several indexes") {
|
||||
t.Fatalf("did not find checker hint for packs in several indexes")
|
||||
}
|
||||
@ -1505,7 +1507,7 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
|
||||
env.gopts.backendTestHook = nil
|
||||
out, err = testRunCheckOutput(env.gopts)
|
||||
out, err = testRunCheckOutput(env.gopts, false)
|
||||
if len(out) != 0 {
|
||||
t.Fatalf("expected no output from the checker, got: %v", out)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user