Skip Oracle tests for Mac users that do not have colima running (#6118)

* Skip Oracle tests for Mac users that do not have colima running

* spotless
This commit is contained in:
Nathan Doef 2024-07-17 13:58:41 -04:00 committed by GitHub
parent 7e7aae6060
commit 912c2da156
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 56 additions and 21 deletions

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.jpa.dao.r5.database; package ca.uhn.fhir.jpa.dao.r5.database;
import ca.uhn.fhir.jpa.embedded.OracleEmbeddedDatabase; import ca.uhn.fhir.jpa.embedded.OracleEmbeddedDatabase;
import ca.uhn.fhir.jpa.embedded.annotation.OracleTest;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirOracleDialect; import ca.uhn.fhir.jpa.model.dialect.HapiFhirOracleDialect;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -9,6 +10,7 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(classes = { @ContextConfiguration(classes = {
DatabaseVerificationWithOracleIT.TestConfig.class DatabaseVerificationWithOracleIT.TestConfig.class
}) })
@OracleTest
public class DatabaseVerificationWithOracleIT extends BaseDatabaseVerificationIT { public class DatabaseVerificationWithOracleIT extends BaseDatabaseVerificationIT {
@Configuration @Configuration

View File

@ -22,8 +22,6 @@ package ca.uhn.fhir.jpa.embedded;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import ca.uhn.fhir.test.utilities.docker.DockerRequiredCondition; import ca.uhn.fhir.test.utilities.docker.DockerRequiredCondition;
import ca.uhn.fhir.util.VersionEnum; import ca.uhn.fhir.util.VersionEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
@ -56,7 +54,7 @@ public class HapiEmbeddedDatabasesExtension implements AfterAllCallback {
myEmbeddedDatabases.add(new H2EmbeddedDatabase()); myEmbeddedDatabases.add(new H2EmbeddedDatabase());
myEmbeddedDatabases.add(new PostgresEmbeddedDatabase()); myEmbeddedDatabases.add(new PostgresEmbeddedDatabase());
myEmbeddedDatabases.add(new MsSqlEmbeddedDatabase()); myEmbeddedDatabases.add(new MsSqlEmbeddedDatabase());
if (canUseOracle()) { if (OracleCondition.canUseOracle()) {
myEmbeddedDatabases.add(new OracleEmbeddedDatabase()); myEmbeddedDatabases.add(new OracleEmbeddedDatabase());
} else { } else {
String message = String message =
@ -133,28 +131,11 @@ public class HapiEmbeddedDatabasesExtension implements AfterAllCallback {
arguments.add(Arguments.of(DriverTypeEnum.POSTGRES_9_4)); arguments.add(Arguments.of(DriverTypeEnum.POSTGRES_9_4));
arguments.add(Arguments.of(DriverTypeEnum.MSSQL_2012)); arguments.add(Arguments.of(DriverTypeEnum.MSSQL_2012));
if (canUseOracle()) { if (OracleCondition.canUseOracle()) {
arguments.add(Arguments.of(DriverTypeEnum.ORACLE_12C)); arguments.add(Arguments.of(DriverTypeEnum.ORACLE_12C));
} }
return arguments.stream(); return arguments.stream();
} }
} }
private static boolean canUseOracle() {
if (!isMac()) {
return true;
}
return isColimaConfigured();
}
private static boolean isMac() {
return SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX;
}
private static boolean isColimaConfigured() {
return StringUtils.isNotBlank(System.getenv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE"))
&& StringUtils.isNotBlank(System.getenv("DOCKER_HOST"))
&& System.getenv("DOCKER_HOST").contains("colima");
}
} }

View File

@ -0,0 +1,38 @@
package ca.uhn.fhir.jpa.embedded;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
public class OracleCondition implements ExecutionCondition {
public static final String ENABLED_MSG = "Environment is able to run Oracle using TestContainers.";
public static final String DISABLED_MSG = "Environment is not able to run Oracle using TestContainers. If you "
+ "are a Mac user, please ensure Colima is running. See: https://java.testcontainers.org/supported_docker_environment/#using-colima.";
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext theExtensionContext) {
return canUseOracle()
? ConditionEvaluationResult.enabled(ENABLED_MSG)
: ConditionEvaluationResult.disabled(DISABLED_MSG);
}
public static boolean canUseOracle() {
if (!isMac()) {
return true;
}
return isColimaConfigured();
}
private static boolean isMac() {
return SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX;
}
private static boolean isColimaConfigured() {
return StringUtils.isNotBlank(System.getenv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE"))
&& StringUtils.isNotBlank(System.getenv("DOCKER_HOST"))
&& System.getenv("DOCKER_HOST").contains("colima");
}
}

View File

@ -0,0 +1,14 @@
package ca.uhn.fhir.jpa.embedded.annotation;
import ca.uhn.fhir.jpa.embedded.OracleCondition;
import org.junit.jupiter.api.extension.ExtendWith;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ExtendWith(OracleCondition.class)
public @interface OracleTest {}