Skip to content

Commit

Permalink
Check if docker-compose is available (#9060)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez authored Aug 5, 2024
1 parent 2758b51 commit 1ce0b1d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.testcontainers.containers;

import org.assertj.core.api.Assumptions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.utility.CommandLine;

import java.io.File;

Expand All @@ -17,16 +20,26 @@ public static Boolean[] local() {
}

@Parameterized.Parameter
public boolean local;
public boolean localMode;

public static final File COMPOSE_FILE = new File("src/test/resources/compose-profile-option/compose-test.yml");

@Before
public void setUp() {
if (this.localMode) {
Assumptions
.assumeThat(CommandLine.executableExists(DockerComposeContainer.COMPOSE_EXECUTABLE))
.as("docker-compose executable exists")
.isTrue();
}
}

@Test
public void testProfileOption() {
try (
DockerComposeContainer<?> compose = new DockerComposeContainer<>(COMPOSE_FILE)
.withOptions("--profile=cache")
.withLocalCompose(this.local)
.withLocalCompose(this.localMode)
) {
compose.start();
assertThat(compose.listChildContainers()).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.testcontainers.junit;

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.Assumptions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.utility.CommandLine;

import java.io.File;
import java.util.Set;
Expand All @@ -19,19 +22,19 @@ public class DockerComposeContainerWithOptionsTest {

public DockerComposeContainerWithOptionsTest(
final File composeFile,
final boolean local,
final boolean localMode,
final Set<String> options,
final boolean expectError
) {
this.composeFile = composeFile;
this.local = local;
this.localMode = localMode;
this.options = options;
this.expectError = expectError;
}

private final File composeFile;

private final boolean local;
private final boolean localMode;

private final Set<String> options;

Expand Down Expand Up @@ -73,12 +76,22 @@ public static Object[][] params() {
};
}

@Before
public void setUp() {
if (this.localMode) {
Assumptions
.assumeThat(CommandLine.executableExists(DockerComposeContainer.COMPOSE_EXECUTABLE))
.as("docker-compose executable exists")
.isTrue();
}
}

@Test
public void performTest() {
try (
DockerComposeContainer<?> environment = new DockerComposeContainer<>(composeFile)
.withOptions(options.stream().toArray(String[]::new))
.withLocalCompose(local)
.withLocalCompose(localMode)
) {
environment.start();
assertThat(expectError).isEqualTo(false);
Expand Down

0 comments on commit 1ce0b1d

Please sign in to comment.