Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify the container network for integration tests #23543

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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