Skip to content

Commit

Permalink
Add ability to read most config properties from env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Oct 20, 2020
1 parent 8bdfd31 commit 58be3e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.testcontainers.UnstableAPI;

Expand Down Expand Up @@ -186,7 +187,7 @@ public Integer getImagePullPauseTimeout() {
*/
@Nullable
@Contract("_, !null -> !null")
public String getEnvVarOrProperty(final String propertyName, @Nullable final String defaultValue) {
public String getEnvVarOrProperty(@NotNull final String propertyName, @Nullable final String defaultValue) {
String envVarName = propertyName.replaceAll("\\.", "_").toUpperCase();
if (!propertyName.startsWith("TESTCONTAINERS_")) {
envVarName = "TESTCONTAINERS_" + envVarName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -22,7 +23,7 @@ public void setUp() {

@Test
public void testHappyPath() {
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY))).thenReturn("someregistry.com/");
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY), any())).thenReturn("someregistry.com/");

final DockerImageName result = underTest.apply(DockerImageName.parse("some/image:tag"));

Expand All @@ -35,7 +36,7 @@ public void testHappyPath() {

@Test
public void testNoDoublePrefixing() {
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY))).thenReturn("someregistry.com/");
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY), any())).thenReturn("someregistry.com/");

final DockerImageName result = underTest.apply(DockerImageName.parse("someregistry.com/some/image:tag"));

Expand All @@ -48,7 +49,7 @@ public void testNoDoublePrefixing() {

@Test
public void testHandlesNullValue() {
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY))).thenReturn(null);
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY), any())).thenReturn(null);

final DockerImageName result = underTest.apply(DockerImageName.parse("some/image:tag"));

Expand All @@ -61,7 +62,7 @@ public void testHandlesNullValue() {

@Test
public void testHandlesEmptyValue() {
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY))).thenReturn("");
when(mockConfiguration.getEnvVarOrProperty(eq(PROPERTY_KEY), any())).thenReturn("");

final DockerImageName result = underTest.apply(DockerImageName.parse("some/image:tag"));

Expand Down

0 comments on commit 58be3e0

Please sign in to comment.