Skip to content

Commit

Permalink
Merge #52221
Browse files Browse the repository at this point in the history
52221: cli: make fewer assumptions about the origin of `stderr` in tests r=irfansharif a=knz

This further removes a dependency on the knowledge that the `log`
package knows anything about stderr, in CLI tests.

Found this while working on #52200.

Release note: None

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
  • Loading branch information
craig[bot] and knz committed Aug 5, 2020
2 parents 8f7a596 + 6eb517f commit f98fe0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type cliTest struct {
*server.TestServer
certsDir string
cleanupFunc func() error
prevStderr *os.File

// t is the testing.T instance used for this test.
// Example_xxx tests may have this set to nil.
Expand Down Expand Up @@ -162,6 +163,7 @@ func newCLITest(params cliTestParams) cliTest {
// Ensure that CLI error messages and anything meant for the
// original stderr is redirected to stdout, where it can be
// captured.
c.prevStderr = stderr
stderr = os.Stdout

return c
Expand Down Expand Up @@ -223,7 +225,7 @@ func (c *cliTest) cleanup() {
}()

// Restore stderr.
stderr = log.OrigStderr
stderr = c.prevStderr

log.Info(context.Background(), "stopping server and cleaning up CLI test")

Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func TestUnavailableZip(t *testing.T) {
t: t,
TestServer: tc.Server(0).(*server.TestServer),
}
defer func(prevStderr *os.File) { stderr = prevStderr }(stderr)
stderr = os.Stdout
defer func() { stderr = log.OrigStderr }()

// Keep the timeout short so that the test doesn't take forever.
out, err := c.RunWithCapture("debug zip --cpu-profile-duration=0 " + os.DevNull + " --timeout=.5s")
Expand Down Expand Up @@ -304,8 +304,8 @@ func TestPartialZip(t *testing.T) {
t: t,
TestServer: tc.Server(0).(*server.TestServer),
}
defer func(prevStderr *os.File) { stderr = prevStderr }(stderr)
stderr = os.Stdout
defer func() { stderr = log.OrigStderr }()

// NB: we spend a second profiling here to make sure it actually tries the
// down nodes (and fails only there, succeeding on the available node).
Expand Down

0 comments on commit f98fe0d

Please sign in to comment.