From 1ce0b1d7ba9e2c4ac2e896799678cf7be620d34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez=20Gonzales?= Date: Mon, 5 Aug 2024 14:55:24 -0500 Subject: [PATCH] Check if docker-compose is available (#9060) --- .../DockerComposeProfilesOptionTest.java | 17 +++++++++++++-- ...DockerComposeContainerWithOptionsTest.java | 21 +++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/org/testcontainers/containers/DockerComposeProfilesOptionTest.java b/core/src/test/java/org/testcontainers/containers/DockerComposeProfilesOptionTest.java index 371525432bf..0f7e41a8454 100644 --- a/core/src/test/java/org/testcontainers/containers/DockerComposeProfilesOptionTest.java +++ b/core/src/test/java/org/testcontainers/containers/DockerComposeProfilesOptionTest.java @@ -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; @@ -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); diff --git a/core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithOptionsTest.java b/core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithOptionsTest.java index 77e60580b39..0de25fa2946 100644 --- a/core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithOptionsTest.java +++ b/core/src/test/java/org/testcontainers/junit/DockerComposeContainerWithOptionsTest.java @@ -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; @@ -19,19 +22,19 @@ public class DockerComposeContainerWithOptionsTest { public DockerComposeContainerWithOptionsTest( final File composeFile, - final boolean local, + final boolean localMode, final Set 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 options; @@ -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);