-
Notifications
You must be signed in to change notification settings - Fork 255
Housekeeping: Use org.testcontainer.*Container #2945
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
Open
ijusti
wants to merge
25
commits into
develop
Choose a base branch
from
feature/org-testcontainers
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
deae913
Use AzuriteContainer from testcontainers-azure module
442d698
Migrate embedded-keycloak to use dasniko/testcontainers-keycloak library
bfc315c
Update to use Testcontainers native Kafka modules and remove embedded…
da57753
Migrate embedded-minio to use MinIOContainer API and remove custom wa…
fac4ff1
Use VaultContainer's withInitCommand for secret initialization and re…
0904899
Migrate embedded-google-pubsub to use PubSubEmulatorContainer from te…
80977d8
Migrate embedded-google-storage to use FakeGcsServerContainer from te…
84babf6
Migrate embedded-memsql to use custom MemSqlContainer extending JdbcD…
deb75e7
Migrate embedded-grafana to use Grafana LGTM stack container with Lok…
8f9f84f
Migrate embedded-wiremock to use WireMockContainer from wiremock-test…
d07eab6
Migrate embedded-nats to use NatsContainer from nats-testcontainers l…
26dd157
Update embedded-wiremock README to reflect WireMockContainer migratio…
07fe840
Migrate embedded-selenium to use Selenium module from testcontainers-…
fd8c7ee
Simplify lambda expressions and use modern Java APIs
3dae065
Refactor code using modern Java APIs and simplify expressions
b461fb6
Update ContainerUtilsTest to use copyToTransferableContainerPathMap i…
b5ca267
Migrate embedded-kafka to use ConfluentKafkaContainer and override co…
ad9f84f
Migrate embedded-native-kafka to use KafkaContainer instead of Conflu…
0ba5346
Refactor embedded-selenium tests to use RemoteWebDriver instead of de…
c12c9ed
Fix MemSQL container startup by creating database before JDBC connect…
9adeec1
Replace LoggerFactory with Lombok @Slf4j annotation in EmbeddedNatsBo…
d5068b9
Replace LoggerFactory with Lombok @Slf4j annotation in EmbeddedNatsBo…
f136cfe
Add HTTPS and OAuth support to embedded Azurite with embedded self-si…
359a639
Add anonymous authentication configuration support to embedded Grafana
021b29f
Enable Toxiproxy for MemSQL and add latency emulation test
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
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
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
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
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
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
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
82 changes: 82 additions & 0 deletions
82
...ed-azurite/src/test/java/com/playtika/testcontainer/azurite/EmbeddedAzuriteHttpsTest.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,82 @@ | ||
| package com.playtika.testcontainer.azurite; | ||
|
|
||
| import com.azure.core.http.netty.NettyAsyncHttpClientBuilder; | ||
| import com.azure.storage.blob.BlobContainerClient; | ||
| import com.azure.storage.blob.BlobServiceClient; | ||
| import com.azure.storage.blob.BlobServiceClientBuilder; | ||
| import io.netty.handler.ssl.SslContextBuilder; | ||
| import io.netty.handler.ssl.util.InsecureTrustManagerFactory; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.testcontainers.azure.AzuriteContainer; | ||
| import reactor.netty.http.client.HttpClient; | ||
|
|
||
| import javax.net.ssl.SSLException; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @SpringBootTest( | ||
| classes = EmbeddedAzuriteHttpsTest.AzuriteHttpsTestConfiguration.class, | ||
| properties = {"embedded.azurite.https-enabled=true"}) | ||
| @Disabled("Create private and public key to check https") | ||
| class EmbeddedAzuriteHttpsTest { | ||
|
|
||
| @Autowired | ||
| AzuriteContainer azuriteContainer; | ||
|
|
||
| @Autowired | ||
| BlobServiceClient blobServiceClient; | ||
|
|
||
| @Value("${embedded.azurite.blob-endpoint}") | ||
| String blobEndpoint; | ||
|
|
||
| @Test | ||
| void blobEndpointUsesHttps() { | ||
| assertThat(blobEndpoint).startsWith("https://"); | ||
| } | ||
|
|
||
| @Test | ||
| void connectionStringUsesHttps() { | ||
| assertThat(azuriteContainer.getConnectionString()).contains("DefaultEndpointsProtocol=https"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("basic blob operations work over HTTPS with the embedded self-signed certificate") | ||
| void createAndDeleteContainerBlobOverHttps() { | ||
| long containersBefore = blobServiceClient.listBlobContainers().stream().count(); | ||
| BlobContainerClient container = blobServiceClient.createBlobContainer(UUID.randomUUID().toString()); | ||
| assertThat(container.listBlobs().stream()).isEmpty(); | ||
| assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore + 1); | ||
| container.delete(); | ||
| assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore); | ||
| } | ||
|
|
||
| @EnableAutoConfiguration | ||
| @Configuration | ||
| static class AzuriteHttpsTestConfiguration { | ||
|
|
||
| @Bean | ||
| BlobServiceClient blobServiceClient(AzuriteContainer azuriteContainer) throws SSLException { | ||
| // Trust all certs so the embedded self-signed certificate is accepted in tests. | ||
| io.netty.handler.ssl.SslContext insecureSslContext = SslContextBuilder.forClient() | ||
| .trustManager(InsecureTrustManagerFactory.INSTANCE) | ||
| .build(); | ||
| HttpClient reactor = HttpClient.create().secure(spec -> spec.sslContext(insecureSslContext)); | ||
| com.azure.core.http.HttpClient azureHttpClient = new NettyAsyncHttpClientBuilder(reactor).build(); | ||
|
|
||
| return new BlobServiceClientBuilder() | ||
| .connectionString(azuriteContainer.getConnectionString()) | ||
| .httpClient(azureHttpClient) | ||
| .buildClient(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: PlaytikaOSS/testcontainers-spring-boot
Length of output: 64
🏁 Script executed:
fd "EmbeddedAzuriteBootstrapConfiguration.java" --exec cat {}Repository: PlaytikaOSS/testcontainers-spring-boot
Length of output: 7654
🏁 Script executed:
Repository: PlaytikaOSS/testcontainers-spring-boot
Length of output: 1089
🌐 Web query:
testcontainers CreateContainerCmd getCmd() null Docker Java SDK💡 Result:
No definitive evidence found of CreateContainerCmd.getCmd returning null in Testcontainers or Docker Java SDK under normal usage. The getCmd method in docker-java's CreateContainerCmd interface returns String[] annotated with
@CheckForNull, meaning it can be null if no command (CMD) has been set via withCmd [1][2][3][4]. Testcontainers' GenericContainer creates a CreateContainerCmd via dockerClient.createContainerCmd(image) and applies modifiers, including command if withCommand is used [5][6]. If no explicit command is set, getCmd may legitimately return null, as the container uses the image's default CMD [7]. No GitHub issues or docs report getCmd unexpectedly null in Testcontainers contexts, including with Testcontainers Desktop [1-33]. Potential related issues include Docker connection problems [8][9][10] or modifier deadlocks [11], but not getCmd null specifically. Ensure withCommand is called if a custom CMD is needed, or check Docker client initialization.Citations:
🌐 Web query:
AzuriteContainer testcontainers withCommand entrypoint💡 Result:
AzuriteContainer is available in multiple Testcontainers libraries for different languages, providing a convenient way to spin up Azurite (Azure Storage emulator) in tests. Official modules handle the default command/entrypoint automatically, matching the Azurite Dockerfile CMD: ["azurite", "-l", "/data", "--blobHost", "0.0.0.0","--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0"][1][2]. To customize using withCommand (overrides CMD) or entrypoint (overrides ENTRYPOINT), use language-specific methods on the AzuriteContainer or underlying GenericContainer: Java (org.testcontainers:azure module): AzuriteContainer extends SingleOffsetMapContainer and configures ports/envs but inherits.withCommand(String... cmd) and.withEntrypoint(String... entrypoint) from GenericContainer[3][4][5]. Example:
AzuriteContainer azurite = new AzuriteContainer("mcr.microsoft.com/azure-storage/azurite:3.33.0") .withCommand("azurite", "--loose", "--blobHost", "0.0.0.0") .withExposedPorts(10000, 10001, 10002); azurite.start();Default usage without custom command: new AzuriteContainer(image).start;[6][5]..NET (Testcontainers.Azurite): Use AzuriteBuilder.WithCommand(params string[] command)[7]. Example for HTTPS:var container = new AzuriteBuilder("mcr.microsoft.com/azure-storage/azurite:latest") .WithCommand("--cert", "/workspace/127.0.0.1.pem", "--key", "/workspace/127.0.0.1-key.pem", "--oauth", "basic") .WithResourceMapping(...) .Build();[6]. Rust (testcontainers-modules): Azurite implements ImageArgsExt.with_cmd(vec![String])[8]. Example:let azurite = Azurite::default().with_cmd(vec!["azurite".to_owned(), "--loose".to_owned()]).start();[8]. Python/Node.js: Specialized methods like withSsl internally handle commands; fall back to GenericContainer equivalents[9][10]. For blob-only:.withCommand("azurite-blob", "--blobHost", "0.0.0.0")[2][11]. Expose only needed ports. Official Testcontainers docs prioritize simple new AzuriteContainer.start as it uses correct defaults[12][6][5]. Custom commands needed for options like --loose, custom ports, SSL[9][7].Citations:
cmd.getCmd()returnsnullwhen no command is explicitly set, causing an NPE viaArrays.asList.The
CreateContainerCmd.getCmd()method is annotated with@CheckForNullin the Docker Java SDK, confirming it can returnnullwhen no command has been set viawithCmd. SinceAzuriteContainerdoes not callwithCommand()internally and relies on the image's default CMD,getCmd()returnsnullwhennew AzuriteContainer(image)is created without prior customization. CallingArrays.asList(cmd.getCmd())on anullinput throws aNullPointerException.Add a null guard to safely handle this case:
Proposed fix
.withCreateContainerCmdModifier(cmd -> { - List<String> args = new ArrayList<>(Arrays.asList(cmd.getCmd())); + String[] existing = cmd.getCmd(); + List<String> args = existing != null ? new ArrayList<>(Arrays.asList(existing)) : new ArrayList<>(); args.add("--skipApiVersionCheck"); cmd.withCmd(args); });📝 Committable suggestion
🤖 Prompt for AI Agents