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

Provide a way to disable QuarkusTests without Docker #869

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
@@ -0,0 +1,26 @@
package io.quarkus.test.scenarios.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Provides option to explicitly enable test only when Linux containers are available.
* The framework automatically detects when Linux containers are needed and only run tests
* when environment supports them. However, you may need to annotate tests with this annotation
* when our framework is not used (like when the QuarkusTest annotation is used).
*/
@Inherited
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(EnabledWhenLinuxContainersAvailableCondition.class)
public @interface EnabledWhenLinuxContainersAvailable {
/**
* Why is the annotated test class or test method disabled.
*/
String reason() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.test.scenarios.annotations;

import static io.quarkus.test.scenarios.execution.condition.AbstractQuarkusScenarioContainerExecutionCondition.ENV_DOES_NOT_SUPPORT_LINUX_CONTAINERS;
import static io.quarkus.test.scenarios.execution.condition.AbstractQuarkusScenarioContainerExecutionCondition.ENV_SUPPORTS_LINUX_CONTAINERS;
import static java.lang.String.format;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import io.quarkus.test.scenarios.execution.condition.AbstractQuarkusScenarioContainerExecutionCondition;

public class EnabledWhenLinuxContainersAvailableCondition implements ExecutionCondition {

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
if (AbstractQuarkusScenarioContainerExecutionCondition.areLinuxContainersSupported()) {
return ENV_SUPPORTS_LINUX_CONTAINERS;
} else {
String testName = extensionContext.getDisplayName();
return disabled(format(ENV_DOES_NOT_SUPPORT_LINUX_CONTAINERS, testName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

public abstract class AbstractQuarkusScenarioContainerExecutionCondition implements QuarkusScenarioExecutionCondition {

public static final ConditionEvaluationResult ENV_SUPPORTS_LINUX_CONTAINERS = enabled("Environment supports"
+ " Linux containers");
public static final String ENV_DOES_NOT_SUPPORT_LINUX_CONTAINERS = "Test class '%s' requires Linux containers, "
+ "but the environment does not support them";
private static final Logger LOG = Logger.getLogger(AbstractQuarkusScenarioContainerExecutionCondition.class.getName());
private static final ConditionEvaluationResult CONDITION_NOT_MATCHED = enabled("This condition should "
+ "only be applied on test classes annotated with the '@QuarkusScenario' annotation");
private static final ConditionEvaluationResult ENV_SUPPORTS_LINUX_CONTAINERS = enabled("Environment supports"
+ " Linux containers");
private static final String ENV_DOES_NOT_SUPPORT_LINUX_CONTAINERS = "Test class '%s' requires Linux containers, "
+ "but the environment does not support them";
private static final String LINUX_CONTAINERS_NOT_REQUIRED = "Test class '%s' does not require containers";
private static final String LINUX_CONTAINER_OS_TYPE = "linux";
private static final String PODMAN = "podman";
Expand Down Expand Up @@ -61,7 +61,7 @@ private ConditionEvaluationResult evaluateExecutionCondition(Class<?> testClass)

protected abstract boolean areContainersRequired(Class<?> testClass);

private static synchronized boolean areLinuxContainersSupported() {
public static synchronized boolean areLinuxContainersSupported() {
if (areLinuxContainersSupported == null) {
areLinuxContainersSupported = checkLinuxContainersSupported();
}
Expand Down