Skip to content
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

Run mongosh or mongo if cmd exists #5774

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.ComparableVersion;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
Expand All @@ -30,8 +29,6 @@ public class MongoDBContainer extends GenericContainer<MongoDBContainer> {

private static final String MONGODB_DATABASE_NAME_DEFAULT = "test";

private final boolean isAtLeastVersion6;

/**
* @deprecated use {@link MongoDBContainer(DockerImageName)} instead
*/
Expand All @@ -48,8 +45,6 @@ public MongoDBContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

this.isAtLeastVersion6 = new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("6.0");

withExposedPorts(MONGODB_INTERNAL_PORT);
withCommand("--replSet", "docker-rs");
waitingFor(Wait.forLogMessage("(?i).*waiting for connections.*", 1));
Expand Down Expand Up @@ -92,8 +87,7 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
}

private String[] buildMongoEvalCommand(final String command) {
String cmd = this.isAtLeastVersion6 ? "mongosh" : "mongo";
return new String[] { cmd, "--eval", command };
return new String[] { "sh", "-c", "mongosh || mongo --eval \"" + command + "\"" };
}

private void checkMongoNodeExitCode(final Container.ExecResult execResult) {
Expand Down