MCPcopy Create free account
hub / github.com/entireio/git-sync / captureStdout

Function captureStdout

cmd/git-sync/main_test.go:670–688  ·  view source on GitHub ↗
(fn func() error)

Source from the content-addressed store, hash-verified

668}
669
670func captureStdout(fn func() error) (string, error) {
671 old := os.Stdout
672 r, w, err := os.Pipe()
673 if err != nil {
674 return "", err
675 }
676 os.Stdout = w
677 defer func() { os.Stdout = old }()
678
679 runErr := fn()
680 _ = w.Close()
681
682 var buf bytes.Buffer
683 if _, err := io.Copy(&buf, r); err != nil {
684 return "", err
685 }
686 _ = r.Close()
687 return strings.TrimSpace(buf.String()), runErr
688}
689
690func newSourceRepo(t *testing.T) (*git.Repository, billy.Filesystem) {
691 t.Helper()

Calls 2

CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected