MCPcopy Index your code
hub / github.com/databus23/helm-diff / captureStdout

Function captureStdout

cmd/helpers_test.go:13–35  ·  view source on GitHub ↗
(f func())

Source from the content-addressed store, hash-verified

11)
12
13func captureStdout(f func()) (string, error) {
14 old := os.Stdout
15 r, w, err := os.Pipe()
16 if err != nil {
17 return "", err
18 }
19 os.Stdout = w
20
21 defer func() {
22 os.Stdout = old
23 }()
24
25 f()
26
27 w.Close()
28
29 var buf bytes.Buffer
30 _, err = io.Copy(&buf, r)
31 if err != nil {
32 return "", err
33 }
34 return buf.String(), nil
35}
36
37func TestCaptureStdout(t *testing.T) {
38 output, err := captureStdout(func() {

Callers 5

TestCaptureStdoutFunction · 0.85
TestDebugPrintFunction · 0.85
TestOutputWithRichErrorFunction · 0.85
TestLocalCmdNoChangesFunction · 0.85
TestLocalCmdWithChangesFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected