-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to test against different Consul versions (#410)
* Modify ConsulTestcontainers to check for a CONSUL_IMAGE_VERSION environment variable. If it exists, run tests against that Docker image. * Make the default Consul image version "latest" so that, unless otherwise specified, tests run against the hashicorp/consul:latest Docker image.
- Loading branch information
1 parent
38a8705
commit ec1e6b7
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 38 additions & 1 deletion
39
src/itest/java/org/kiwiproject/consul/ConsulTestcontainers.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 |
---|---|---|
@@ -1,10 +1,47 @@ | ||
package org.kiwiproject.consul; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ConsulTestcontainers { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ConsulTestcontainers.class); | ||
|
||
private ConsulTestcontainers() { | ||
// utility class | ||
} | ||
|
||
public static final String CONSUL_DOCKER_IMAGE_NAME = "hashicorp/consul:1.16.1"; | ||
/** | ||
* The name of the environment variable that defines the Consul Docker image version. | ||
* <p> | ||
* If you want to run the tests against a specific Consul Docker image, set this | ||
* environment variable to the version you want. It should match a valid tag name | ||
* in the hashicorp/consul | ||
* <a href="https://hub.docker.com/r/hashicorp/consul/tags">container images</a> | ||
* such as {@code "latest"}, {@code "1.20"}, or a more specific version such as {@code "1.19.1"}. | ||
*/ | ||
public static final String CONSUL_DOCKER_IMAGE_VERSION_ENV_VAR = "CONSUL_IMAGE_VERSION"; | ||
|
||
/** | ||
* The name of the Consul Docker container image to use, e.g., {@code "hashicorp/consul:latest"} | ||
* or {@code "hashicorp/consul:1.20"}. | ||
* <p> | ||
* By default, this will be {@code "hashicorp/consul:latest"}. To change the value, you can | ||
* set the {@code CONSUL_IMAGE_VERSION} environment variable to the <em>tag name</em> that you | ||
* want to use, such as {@code "1.18.2"}. The prefix is automatically prepended to the | ||
* version. | ||
* | ||
* @see #CONSUL_DOCKER_IMAGE_VERSION_ENV_VAR | ||
*/ | ||
public static final String CONSUL_DOCKER_IMAGE_NAME = consulImageNameFromEnvOrLatest(); | ||
|
||
private static String consulImageNameFromEnvOrLatest() { | ||
var value = System.getenv(CONSUL_DOCKER_IMAGE_VERSION_ENV_VAR); | ||
var consulVersion = isNull(value) ? "latest" : value; | ||
var imageName = "hashicorp/consul:" + consulVersion; | ||
LOG.info("Using Consul container image: {}", imageName); | ||
return imageName; | ||
} | ||
} |