mirror of
https://github.com/restic/restic.git
synced 2026-05-11 13:05:23 +00:00
test: add helper to capture stdout for integration tests
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
@@ -16,20 +15,14 @@ import (
|
||||
)
|
||||
|
||||
func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf, err := withCaptureStdout(func() error {
|
||||
gopts.stdout = globalOptions.stdout
|
||||
|
||||
globalOptions.stdout = buf
|
||||
oldStdout := gopts.stdout
|
||||
gopts.stdout = buf
|
||||
defer func() {
|
||||
globalOptions.stdout = os.Stdout
|
||||
gopts.stdout = oldStdout
|
||||
}()
|
||||
|
||||
opts := DiffOptions{
|
||||
ShowMetadata: false,
|
||||
}
|
||||
err := runDiff(context.TODO(), opts, gopts, []string{firstSnapshotID, secondSnapshotID})
|
||||
opts := DiffOptions{
|
||||
ShowMetadata: false,
|
||||
}
|
||||
return runDiff(context.TODO(), opts, gopts, []string{firstSnapshotID, secondSnapshotID})
|
||||
})
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user