-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch tests to use Testcontainers (#245)
Closes #244
- Loading branch information
1 parent
288aad0
commit 22e99dc
Showing
4 changed files
with
75 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
src/test/java/org/kiwiproject/migrations/mongo/MongoTestContainerHelpers.java
This file contains 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,34 @@ | ||
package org.kiwiproject.migrations.mongo; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.testcontainers.containers.MongoDBContainer; | ||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@UtilityClass | ||
@Slf4j | ||
public class MongoTestContainerHelpers { | ||
|
||
public static final String ENV_MONGO_IMAGE_NAME = "MONGO_IMAGE_NAME"; | ||
|
||
public static final String MONGO_LATEST_IMAGE_NAME = "mongo:latest"; | ||
|
||
public static MongoDBContainer newMongoDBContainer() { | ||
var imageName = envMongoImageNameOrLatest(); | ||
return newMongoDBContainer(imageName); | ||
} | ||
|
||
private static String envMongoImageNameOrLatest() { | ||
var envImageName = System.getenv(ENV_MONGO_IMAGE_NAME); | ||
return isNull(envImageName) ? MONGO_LATEST_IMAGE_NAME : envImageName; | ||
} | ||
|
||
@SuppressWarnings("resource") // because Testcontainers closes it for us | ||
public static MongoDBContainer newMongoDBContainer(String dockerImageName) { | ||
LOG.info("Create MongoDBContainer for Docker image name: {}", dockerImageName); | ||
return new MongoDBContainer(DockerImageName.parse(dockerImageName)).waitingFor(new HostPortWaitStrategy()); | ||
} | ||
} |