-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reset value in Docker Compose
Fixes #7919
- Loading branch information
1 parent
dee4cbe
commit 1c7f7cb
Showing
4 changed files
with
68 additions
and
7 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
41 changes: 41 additions & 0 deletions
41
core/src/test/java/org/testcontainers/junit/ComposeContainerOverrideTest.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,41 @@ | ||
package org.testcontainers.junit; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.command.InspectContainerResponse; | ||
import org.junit.Test; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.ComposeContainer; | ||
import org.testcontainers.containers.ContainerState; | ||
|
||
import java.io.File; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ComposeContainerOverrideTest { | ||
|
||
private static final File BASE = new File("src/test/resources/compose-override/compose.yml"); | ||
|
||
private static final File OVERRIDE = new File("src/test/resources/compose-override/compose-override.yml"); | ||
|
||
@Test | ||
public void readEnvironment() { | ||
try (ComposeContainer compose = new ComposeContainer(BASE).withExposedService("redis", 6379)) { | ||
compose.start(); | ||
DockerClient dockerClient = DockerClientFactory.lazyClient(); | ||
String containerId = compose.getContainerByServiceName("redis-1").map(ContainerState::getContainerId).get(); | ||
InspectContainerResponse container = dockerClient.inspectContainerCmd(containerId).exec(); | ||
assertThat(container.getConfig().getEnv()).contains("foo=bar"); | ||
} | ||
} | ||
|
||
@Test | ||
public void resetEnvironment() { | ||
try (ComposeContainer compose = new ComposeContainer(BASE, OVERRIDE).withExposedService("redis", 6379)) { | ||
compose.start(); | ||
DockerClient dockerClient = DockerClientFactory.lazyClient(); | ||
String containerId = compose.getContainerByServiceName("redis-1").map(ContainerState::getContainerId).get(); | ||
InspectContainerResponse container = dockerClient.inspectContainerCmd(containerId).exec(); | ||
assertThat(container.getConfig().getEnv()).doesNotContain("foo=bar"); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/test/resources/compose-override/compose-override.yml
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,7 @@ | ||
services: | ||
redis: | ||
image: redis:6-alpine | ||
ports: | ||
- 6379 | ||
environment: | ||
foo: !reset null |
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,7 @@ | ||
services: | ||
redis: | ||
image: redis:6-alpine | ||
ports: | ||
- 6379 | ||
environment: | ||
foo: bar |