-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove extra newlines in container log output #3752
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
Merged
bsideup
merged 2 commits into
testcontainers:master
from
perlun:fix/remove-extra-newlines
Feb 10, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
core/src/test/java/org/testcontainers/containers/output/ToStringConsumerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.testcontainers.containers.output; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.apache.commons.lang.RandomStringUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
import org.testcontainers.containers.Container.ExecResult; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; | ||
|
||
public class ToStringConsumerTest { | ||
|
||
private static final String LARGE_PAYLOAD; | ||
|
||
static { | ||
StringBuilder builder = new StringBuilder(10_003 * 10);; | ||
for (int i = 0; i < 10; i++) { | ||
builder.append(' ').append(i).append(RandomStringUtils.randomAlphabetic(10000)); | ||
} | ||
LARGE_PAYLOAD = builder.toString(); | ||
Assertions.assertThat(LARGE_PAYLOAD).doesNotContain("\n"); | ||
} | ||
|
||
@Test | ||
public void newlines_are_not_added_to_exec_output() throws Exception { | ||
try (GenericContainer<?> container = new GenericContainer<>("alpine:3.13")) { | ||
container.withCommand("sleep", "2m"); | ||
container.start(); | ||
|
||
ExecResult build = container.execInContainer("echo", "-n", LARGE_PAYLOAD); | ||
Assertions.assertThat(build.getStdout()) | ||
.doesNotContain("\n") | ||
.isEqualTo(LARGE_PAYLOAD); | ||
} | ||
} | ||
|
||
@Test(timeout = 60_000L) | ||
public void newlines_are_not_added_to_exec_output_with_tty() throws Exception { | ||
try (GenericContainer<?> container = new GenericContainer<>("alpine:3.13")) { | ||
container.withCreateContainerCmdModifier(cmd -> { | ||
cmd | ||
.withAttachStdin(true) | ||
.withStdinOpen(true) | ||
.withTty(true); | ||
}); | ||
container.withCommand("sleep", "2m"); | ||
container.start(); | ||
|
||
ExecResult build = container.execInContainer("echo", "-n", LARGE_PAYLOAD); | ||
assertThat(build.getStdout()) | ||
.isEqualTo(LARGE_PAYLOAD) | ||
.doesNotContain("\n"); | ||
} | ||
} | ||
|
||
@Test | ||
public void newlines_are_not_added_to_container_output() { | ||
try (GenericContainer<?> container = new GenericContainer<>("alpine:3.13")) { | ||
container.withCommand("echo", "-n", LARGE_PAYLOAD); | ||
container.setStartupCheckStrategy(new OneShotStartupCheckStrategy()); | ||
container.start(); | ||
|
||
container.getDockerClient().waitContainerCmd(container.getContainerId()).start().awaitStatusCode(); | ||
|
||
assertThat(container.getLogs()) | ||
.isEqualTo(LARGE_PAYLOAD) | ||
.doesNotContain("\n"); | ||
} | ||
} | ||
|
||
@Test | ||
public void newlines_are_not_added_to_container_output_with_tty() { | ||
try (GenericContainer<?> container = new GenericContainer<>("alpine:3.13")) { | ||
container.withCreateContainerCmdModifier(cmd -> { | ||
cmd.withTty(true); | ||
}); | ||
container.withCommand("echo", "-n", LARGE_PAYLOAD); | ||
container.setStartupCheckStrategy(new OneShotStartupCheckStrategy()); | ||
container.start(); | ||
|
||
container.getDockerClient().waitContainerCmd(container.getContainerId()).start().awaitStatusCode(); | ||
|
||
assertThat(container.getLogs()) | ||
.isEqualTo(LARGE_PAYLOAD) | ||
.doesNotContain("\n"); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This essentially reverts the change done here: https://github.com/testcontainers/testcontainers-java/pull/643/files#diff-321431024ed34199142ebf2d70a46ba89f8a09e66582d40527885123e429b4d9R22-R24
It's not entirely clear to me if this will work for all use cases; it could very well be that this breaks (so it might be that we'll have to conditionalize it). I was unable to run all the tests locally, so maybe CI will shed some light on this.