Skip to content

Commit

Permalink
Merge pull request #869 from michalvavrik/feature/quarkus-tests-needs…
Browse files Browse the repository at this point in the history
…-a-way-to-disable-on-docker

Provide a way to disable QuarkusTests without Docker
  • Loading branch information
michalvavrik authored Sep 1, 2023
2 parents a135f85 + 9039269 commit e977344
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
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

0 comments on commit e977344

Please sign in to comment.