Skip to content

Commit

Permalink
Support Elastisearch image from DockerHub (#7777)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Nov 8, 2023
1 parent dd24851 commit 3b7c2eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Testcontainers implementation for Elasticsearch.
* <p>
* Supported image: {@code docker.elastic.co/elasticsearch/elasticsearch}
* Supported image: {@code docker.elastic.co/elasticsearch/elasticsearch}, {@code elasticsearch}
* <p>
* Exposed ports:
* <ul>
Expand Down Expand Up @@ -64,6 +64,8 @@ public class ElasticsearchContainer extends GenericContainer<ElasticsearchContai
"docker.elastic.co/elasticsearch/elasticsearch-oss"
);

private static final DockerImageName ELASTICSEARCH_IMAGE_NAME = DockerImageName.parse("elasticsearch");

/**
* Elasticsearch Default version
*/
Expand Down Expand Up @@ -100,7 +102,7 @@ public ElasticsearchContainer(String dockerImageName) {
*/
public ElasticsearchContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, DEFAULT_OSS_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, DEFAULT_OSS_IMAGE_NAME, ELASTICSEARCH_IMAGE_NAME);
this.isOss = dockerImageName.isCompatibleWith(DEFAULT_OSS_IMAGE_NAME);

withNetworkAliases("elasticsearch-" + Base58.randomString(6));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,16 @@ public void testElasticsearch8SecureByDefault() throws Exception {
// Start the container. This step might take some time...
container.start();

Response response = getClusterHealth(container);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");
assertClusterHealthResponse(container);
}
}

@Test
public void testDockerHubElasticsearch8ImageSecureByDefault() throws Exception {
try (ElasticsearchContainer container = new ElasticsearchContainer("elasticsearch:8.1.2")) {
container.start();

assertClusterHealthResponse(container);
}
}

Expand Down Expand Up @@ -351,9 +358,7 @@ public void testElasticsearch8SecureByDefaultHttpWaitStrategy() throws Exception
// Start the container. This step might take some time...
container.start();

Response response = getClusterHealth(container);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");
assertClusterHealthResponse(container);
}
}

Expand Down Expand Up @@ -488,4 +493,10 @@ private void assertElasticsearchContainerHasHeapSize(ElasticsearchContainer cont
assertThat(responseBody).contains("\"heap_init_in_bytes\":" + heapSizeInBytes);
assertThat(responseBody).contains("\"heap_max_in_bytes\":" + heapSizeInBytes);
}

private void assertClusterHealthResponse(ElasticsearchContainer container) throws IOException {
Response response = getClusterHealth(container);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");
}
}

0 comments on commit 3b7c2eb

Please sign in to comment.