mirror of
https://github.com/restic/restic.git
synced 2024-12-27 10:17:58 +00:00
test: print log output if testRunCheck fails
This commit is contained in:
parent
419e6f26b1
commit
06fd6b54d7
2 changed files with 18 additions and 16 deletions
|
@ -64,7 +64,7 @@ func TestRepairSnapshotsWithLostData(t *testing.T) {
|
||||||
// repository must be ok after removing the broken snapshots
|
// repository must be ok after removing the broken snapshots
|
||||||
testRunForget(t, env.gopts, snapshotIDs[0].String(), snapshotIDs[1].String())
|
testRunForget(t, env.gopts, snapshotIDs[0].String(), snapshotIDs[1].String())
|
||||||
testListSnapshots(t, env.gopts, 2)
|
testListSnapshots(t, env.gopts, 2)
|
||||||
_, err := testRunCheckOutput(env.gopts)
|
_, err := testRunCheckOutput(env.gopts, false)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ func TestRepairSnapshotsWithLostTree(t *testing.T) {
|
||||||
testRunRebuildIndex(t, env.gopts)
|
testRunRebuildIndex(t, env.gopts)
|
||||||
testRunRepairSnapshot(t, env.gopts, true)
|
testRunRepairSnapshot(t, env.gopts, true)
|
||||||
testListSnapshots(t, env.gopts, 1)
|
testListSnapshots(t, env.gopts, 1)
|
||||||
_, err := testRunCheckOutput(env.gopts)
|
_, err := testRunCheckOutput(env.gopts, false)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func TestRepairSnapshotsWithLostRootTree(t *testing.T) {
|
||||||
testRunRebuildIndex(t, env.gopts)
|
testRunRebuildIndex(t, env.gopts)
|
||||||
testRunRepairSnapshot(t, env.gopts, true)
|
testRunRepairSnapshot(t, env.gopts, true)
|
||||||
testListSnapshots(t, env.gopts, 0)
|
testListSnapshots(t, env.gopts, 0)
|
||||||
_, err := testRunCheckOutput(env.gopts)
|
_, err := testRunCheckOutput(env.gopts, false)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,14 +150,20 @@ func testRunRestoreAssumeFailure(snapshotID string, opts RestoreOptions, gopts G
|
||||||
|
|
||||||
func testRunCheck(t testing.TB, gopts GlobalOptions) {
|
func testRunCheck(t testing.TB, gopts GlobalOptions) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
opts := CheckOptions{
|
output, err := testRunCheckOutput(gopts, true)
|
||||||
ReadData: true,
|
if err != nil {
|
||||||
CheckUnused: true,
|
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)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
globalOptions.stdout = buf
|
globalOptions.stdout = buf
|
||||||
|
@ -166,18 +172,14 @@ func testRunCheckOutput(gopts GlobalOptions) (string, error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
opts := CheckOptions{
|
opts := CheckOptions{
|
||||||
ReadData: true,
|
ReadData: true,
|
||||||
|
CheckUnused: checkUnused,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := runCheck(context.TODO(), opts, gopts, nil)
|
err := runCheck(context.TODO(), opts, gopts, nil)
|
||||||
return buf.String(), err
|
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) {
|
func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
||||||
buf := bytes.NewBuffer(nil)
|
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")
|
datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz")
|
||||||
rtest.SetupTarTestFixture(t, env.base, datafile)
|
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") {
|
if !strings.Contains(out, "contained in several indexes") {
|
||||||
t.Fatalf("did not find checker hint for packs 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)
|
testRunRebuildIndex(t, env.gopts)
|
||||||
|
|
||||||
env.gopts.backendTestHook = nil
|
env.gopts.backendTestHook = nil
|
||||||
out, err = testRunCheckOutput(env.gopts)
|
out, err = testRunCheckOutput(env.gopts, false)
|
||||||
if len(out) != 0 {
|
if len(out) != 0 {
|
||||||
t.Fatalf("expected no output from the checker, got: %v", out)
|
t.Fatalf("expected no output from the checker, got: %v", out)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue