2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-03 02:18:23 +00:00
restic/cmd/restic/cmd_check_integration_test.go
Michael Eischer 939b537c80 check/migrate: convert to use termstatus to prevent mangled output
Errors reported by check would result in corrupted output.
2024-05-30 15:09:27 +02:00

39 lines
955 B
Go

package main
import (
"bytes"
"context"
"testing"
rtest "github.com/restic/restic/internal/test"
"github.com/restic/restic/internal/ui/termstatus"
)
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 := bytes.NewBuffer(nil)
gopts.stdout = buf
err := withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error {
opts := CheckOptions{
ReadData: true,
CheckUnused: checkUnused,
}
return runCheck(context.TODO(), opts, gopts, nil, term)
})
return buf.String(), err
}