summaryrefslogtreecommitdiff
path: root/cmd/restic/cmd_check_integration_test.go
blob: 9eb4fec62a1d56d5c8a527c465339389cddfee0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"context"
	"testing"

	rtest "github.com/restic/restic/internal/test"
)

func testRunCheck(t testing.TB, gopts GlobalOptions) {
	t.Helper()
	output, err := testRunCheckOutput(gopts, true)
	if err != nil {
		t.Error(output)
		t.Fatalf("unexpected error: %+v", err)
	}
}

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, err := withCaptureStdout(func() error {
		opts := CheckOptions{
			ReadData:    true,
			CheckUnused: checkUnused,
		}
		return runCheck(context.TODO(), opts, gopts, nil)
	})
	return buf.String(), err
}