MCPcopy Create free account
hub / github.com/dropbox/dbxcli / captureStdout

Function captureStdout

cmd/auth_test.go:16–39  ·  view source on GitHub ↗
(t *testing.T, fn func())

Source from the content-addressed store, hash-verified

14)
15
16func captureStdout(t *testing.T, fn func()) string {
17 t.Helper()
18
19 oldStdout := os.Stdout
20 r, w, err := os.Pipe()
21 if err != nil {
22 t.Fatal(err)
23 }
24 os.Stdout = w
25 defer func() {
26 os.Stdout = oldStdout
27 }()
28
29 fn()
30
31 if err := w.Close(); err != nil {
32 t.Fatal(err)
33 }
34 out, err := io.ReadAll(r)
35 if err != nil {
36 t.Fatal(err)
37 }
38 return string(out)
39}
40
41func TestAuthFilePathUsesEnv(t *testing.T) {
42 authFile := filepath.Join(t.TempDir(), "custom-auth.json")

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected