Skip to content

Commit

Permalink
Similar to AppCDSBuildStep, IntegrationTestUtil needs to handle a sit…
Browse files Browse the repository at this point in the history
…uation\nwhere there is no container runtime working and none is needed.
  • Loading branch information
Karm committed Mar 16, 2023
1 parent f8c61cf commit 781eb53
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import io.quarkus.paths.PathList;
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.logging.LoggingSetupRecorder;
import io.quarkus.runtime.util.ContainerRuntimeUtil;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.PathTestHelper;
Expand All @@ -64,7 +65,7 @@ public final class IntegrationTestUtil {
public static final int DEFAULT_PORT = 8081;
public static final int DEFAULT_HTTPS_PORT = 8444;
public static final long DEFAULT_WAIT_TIME_SECONDS = 60;
private static final String DOCKER_BINARY = detectContainerRuntime().getExecutableName();
public static final ContainerRuntimeUtil.ContainerRuntime CONTAINER_RUNTIME = detectContainerRuntime(false);

private IntegrationTestUtil() {
}
Expand Down Expand Up @@ -336,9 +337,15 @@ public void accept(String s, String s2) {
private static void createNetworkIfNecessary(
final ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult) {
if (devServicesLaunchResult.manageNetwork() && (devServicesLaunchResult.networkId() != null)) {
if (CONTAINER_RUNTIME == ContainerRuntimeUtil.ContainerRuntime.UNAVAILABLE) {
throw new IllegalStateException("No container runtime was found. "
+ "Make sure you have either Docker or Podman installed in your environment.");
}
try {
int networkCreateResult = new ProcessBuilder().redirectError(DISCARD).redirectOutput(DISCARD)
.command(DOCKER_BINARY, "network", "create", devServicesLaunchResult.networkId()).start().waitFor();
.command(CONTAINER_RUNTIME.getExecutableName(), "network", "create",
devServicesLaunchResult.networkId())
.start().waitFor();
if (networkCreateResult > 0) {
throw new RuntimeException("Creating container network '" + devServicesLaunchResult.networkId()
+ "' completed unsuccessfully");
Expand All @@ -349,7 +356,9 @@ private static void createNetworkIfNecessary(
public void run() {
try {
new ProcessBuilder().redirectError(DISCARD).redirectOutput(DISCARD)
.command(DOCKER_BINARY, "network", "rm", devServicesLaunchResult.networkId()).start()
.command(CONTAINER_RUNTIME.getExecutableName(), "network", "rm",
devServicesLaunchResult.networkId())
.start()
.waitFor();
} catch (InterruptedException | IOException ignored) {
System.out.println(
Expand Down

0 comments on commit 781eb53

Please sign in to comment.