-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Docker compose
withOptions(...)
(#2827)
Co-authored-by: Peter Lewis <Peter.Lewis@nagra.com> Co-authored-by: Richard North <rich.north@gmail.com>
- Loading branch information
1 parent
e01495d
commit 77251a1
Showing
3 changed files
with
96 additions
and
1 deletion.
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
62 changes: 62 additions & 0 deletions
62
core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithOptionsTest.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,62 @@ | ||
package org.testcontainers.junit; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.testcontainers.containers.DockerComposeContainer; | ||
|
||
import java.io.File; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests the options associated with the docker-compose command. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class DockerComposeContainerWithOptionsTest { | ||
|
||
public DockerComposeContainerWithOptionsTest(final File composeFile, final boolean local, final Set<String> options, final boolean expectError) { | ||
this.composeFile = composeFile; | ||
this.local = local; | ||
this.options = options; | ||
this.expectError = expectError; | ||
} | ||
|
||
private final File composeFile; | ||
private final boolean local; | ||
|
||
private final Set<String> options; | ||
private final boolean expectError; | ||
|
||
@Parameterized.Parameters(name = "docker-compose test [compose file: {0}, local: {1}, options: {2}, expected result: {3}]") | ||
|
||
public static Object[][] params() { | ||
return new Object[][]{ | ||
// Test the happy day case. THe compatibility option should be accepted by docker-compose. | ||
{new File("src/test/resources/compose-options-test/with-deploy-block.yml"), false, ImmutableSet.of("--compatibility"), false}, | ||
// Test with flags absent. Docker compose will warn but continue, ignoring the deploy block. | ||
{new File("src/test/resources/compose-options-test/with-deploy-block.yml"), false, ImmutableSet.of(""), false}, | ||
// Test with a bad option. Compose will complain. | ||
{new File("src/test/resources/compose-options-test/with-deploy-block.yml"), false, ImmutableSet.of("--bad-option"), true}, | ||
// Local compose | ||
{new File("src/test/resources/compose-options-test/with-deploy-block.yml"), true, ImmutableSet.of("--compatibility"), false}, | ||
}; | ||
} | ||
|
||
@Test | ||
public void performTest() { | ||
|
||
try (DockerComposeContainer<?> environment = new DockerComposeContainer<>(composeFile) | ||
.withOptions(options.stream().toArray(String[]::new)) | ||
.withLocalCompose(local)) { | ||
environment.start(); | ||
assertThat(expectError).isEqualTo(false); | ||
} catch (Exception e) { | ||
assertThat(expectError).isEqualTo(true); | ||
} | ||
|
||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/compose-options-test/with-deploy-block.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,8 @@ | ||
version: '3.7' | ||
services: | ||
redis: | ||
image: redis:2.6.17 | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 150M |