Skip to content

Commit

Permalink
Merge pull request #23543 from geoand/#23531
Browse files Browse the repository at this point in the history
Allow users to specify the container network for integration tests
  • Loading branch information
geoand authored Feb 9, 2022
2 parents 729e332 + 96d3001 commit c7c39f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public class TestConfig {
@ConfigItem
Profile profile;

/**
* Container related test settings
*/
@ConfigItem
Container container;

/**
* Additional launch parameters to be used when Quarkus launches the produced artifact for {@code @QuarkusIntegrationTest}
* When the artifact is a {@code jar}, this string is passed right after the {@code java} command.
Expand Down Expand Up @@ -232,6 +238,19 @@ public static class Profile {
Optional<List<String>> tags;
}

@ConfigGroup
public static class Container {

/**
* Controls the container network to be used when @QuarkusIntegration needs to launch the application in a container.
* This setting only applies if Quarkus does not need to use a shared network - which is the case if DevServices are
* used
* when running the test.
*/
@ConfigItem
Optional<String> network;
}

public enum Mode {
PAUSED,
ENABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.function.BiConsumer;
Expand All @@ -32,6 +33,7 @@
import javax.inject.Inject;

import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.microprofile.config.Config;
import org.jboss.jandex.Index;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.JUnitException;
Expand All @@ -49,6 +51,7 @@
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.logging.LoggingSetupRecorder;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.PathTestHelper;
import io.quarkus.test.common.TestClassIndexer;
import io.quarkus.test.common.TestResourceManager;
Expand Down Expand Up @@ -305,8 +308,17 @@ public void accept(String s, String s2) {
Object sharedNetwork = networkClass.getField("SHARED").get(null);
networkId = (String) networkClass.getMethod("getId").invoke(sharedNetwork);
} catch (Exception e) {
networkId = "quarkus-integration-test-" + RandomStringUtils.random(5, true, false);
manageNetwork = true;
// use the network the use has specified or else just generate one if none is configured

Config config = LauncherUtil.installAndGetSomeConfig();
Optional<String> networkIdOpt = config
.getOptionalValue("quarkus.test.container.network", String.class);
if (networkIdOpt.isPresent()) {
networkId = networkIdOpt.get();
} else {
networkId = "quarkus-integration-test-" + RandomStringUtils.random(5, true, false);
manageNetwork = true;
}
}
}

Expand Down

0 comments on commit c7c39f6

Please sign in to comment.