test: add helper to capture stdout for integration tests

This commit is contained in:
Michael Eischer
2023-05-07 22:06:39 +02:00
parent 675a49a95b
commit cebce52c16
12 changed files with 93 additions and 133 deletions
+7 -14
View File
@@ -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
}