-
Notifications
You must be signed in to change notification settings - Fork 89
[Draft] Add stderr to process result output #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ public void before() throws IOException { | |
| dockerComposeCommand = new Command(dockerComposeExecutable, logConsumer); | ||
|
|
||
| givenTheUnderlyingProcessHasOutput(""); | ||
| givenTheUnderlyingProcessHasError(""); | ||
| givenTheUnderlyingProcessTerminatesWithAnExitCodeOf(0); | ||
| } | ||
|
|
||
|
|
@@ -72,7 +73,7 @@ public void return_output_when_exit_code_of_the_executed_process_is_non_0() | |
| givenTheUnderlyingProcessHasOutput(expectedOutput); | ||
| String commandOutput = dockerComposeCommand.execute(errorHandler, "rm", "-f"); | ||
|
|
||
| assertThat(commandOutput).isEqualTo(expectedOutput); | ||
| assertThat(commandOutput).isEqualTo("STDERR: <empty>\n\n------\n\nSTDOUT: " + expectedOutput + "\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with multi line strings you should be able to do something like: assertThat(commandOutput).isEqualTo(
"""
STDERR: <empty>
------
STDOUT: %s
""", expectedOutput);assertj has some nice utility methods to do string formatting inside
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also gives me a way to see what the actual error message would look like. So much so, I would actually just put the content for each stream on a new line e.g. |
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -81,7 +82,29 @@ public void return_output_when_exit_code_of_the_executed_process_is_0() throws I | |
| givenTheUnderlyingProcessHasOutput(expectedOutput); | ||
| String commandOutput = dockerComposeCommand.execute(errorHandler, "rm", "-f"); | ||
|
|
||
| assertThat(commandOutput).isEqualTo(expectedOutput); | ||
| assertThat(commandOutput).isEqualTo("STDERR: <empty>\n\n------\n\nSTDOUT: " + expectedOutput + "\n"); | ||
| } | ||
|
|
||
| @Test | ||
| public void return_output_when_only_stderr_is_present() throws IOException, InterruptedException { | ||
| String expectedStderr = "error output"; | ||
| givenTheUnderlyingProcessHasError(expectedStderr); | ||
| String commandOutput = dockerComposeCommand.execute(errorHandler, "rm", "-f"); | ||
|
|
||
| assertThat(commandOutput) | ||
| .isEqualTo("STDERR: " + expectedStderr + "\n\n------\n\nSTDOUT: <empty>\n"); | ||
| } | ||
|
|
||
| @Test | ||
| public void return_output_containing_both_stderr_and_stdout() throws IOException, InterruptedException { | ||
| String expectedStdout = "standard output"; | ||
| String expectedStderr = "error output"; | ||
| givenTheUnderlyingProcessHasOutput(expectedStdout); | ||
| givenTheUnderlyingProcessHasError(expectedStderr); | ||
| String commandOutput = dockerComposeCommand.execute(errorHandler, "rm", "-f"); | ||
|
|
||
| assertThat(commandOutput) | ||
| .isEqualTo("STDERR: " + expectedStderr + "\n\n------\n\nSTDOUT: " + expectedStdout + "\n"); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -94,6 +117,16 @@ public void give_the_output_to_the_specified_consumer_as_it_is_available() | |
| assertThat(consumedLogLines).containsExactly("line 1", "line 2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void give_both_stdout_and_stderr_to_the_specified_consumer() throws IOException, InterruptedException { | ||
| givenTheUnderlyingProcessHasOutput("stdout line"); | ||
| givenTheUnderlyingProcessHasError("stderr line"); | ||
|
|
||
| dockerComposeCommand.execute(errorHandler, "rm", "-f"); | ||
|
|
||
| assertThat(consumedLogLines).containsExactly("stdout line", "stderr line"); | ||
| } | ||
|
|
||
| // flaky test: https://circleci.com/gh/palantir/docker-compose-rule/378, 370, 367, 366 | ||
| @Ignore | ||
| @Test | ||
|
|
@@ -110,6 +143,10 @@ private void givenTheUnderlyingProcessHasOutput(String output) { | |
| when(executedProcess.getInputStream()).thenReturn(toInputStream(output)); | ||
| } | ||
|
|
||
| private void givenTheUnderlyingProcessHasError(String error) { | ||
| when(executedProcess.getErrorStream()).thenReturn(toInputStream(error)); | ||
| } | ||
|
|
||
| private void givenTheUnderlyingProcessTerminatesWithAnExitCodeOf(int exitCode) { | ||
| when(executedProcess.exitValue()).thenReturn(exitCode); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just use multi line strings here?