From 81886fa09796d995591b15ef8647175807f2ff4a Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 22 Apr 2024 22:59:04 -0400 Subject: [PATCH] Don't download MaxMind dbs in tests --- .../me/braydon/mc/common/EnvironmentUtils.java | 17 ++++++++++++++++- .../me/braydon/mc/service/MaxMindService.java | 6 +++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/API/src/main/java/me/braydon/mc/common/EnvironmentUtils.java b/API/src/main/java/me/braydon/mc/common/EnvironmentUtils.java index ef4c2eb..bd1b412 100644 --- a/API/src/main/java/me/braydon/mc/common/EnvironmentUtils.java +++ b/API/src/main/java/me/braydon/mc/common/EnvironmentUtils.java @@ -35,8 +35,23 @@ public final class EnvironmentUtils { * Is the app running in a production environment? */ @Getter private static final boolean production; - static { // Are we running on production? + + /** + * Is the app running in a test environment? + */ + @Getter private static boolean testing; + + static { + // Are we running on production? String env = System.getenv("APP_ENV"); production = env != null && (env.equals("production")); + + // Are we running in a test? + try { + Class.forName("org.junit.Test"); + testing = true; + } catch (ClassNotFoundException ignored) { + // Safely ignore + } } } \ No newline at end of file diff --git a/API/src/main/java/me/braydon/mc/service/MaxMindService.java b/API/src/main/java/me/braydon/mc/service/MaxMindService.java index 31b4b0f..34b278e 100644 --- a/API/src/main/java/me/braydon/mc/service/MaxMindService.java +++ b/API/src/main/java/me/braydon/mc/service/MaxMindService.java @@ -30,6 +30,7 @@ import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import lombok.*; import lombok.extern.log4j.Log4j2; +import me.braydon.mc.common.EnvironmentUtils; import org.apache.commons.io.FileUtils; import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver; import org.springframework.beans.factory.annotation.Value; @@ -70,7 +71,10 @@ public final class MaxMindService { @PostConstruct public void onInitialize() { - loadDatabases(); // Load the databases + // Load the databases + if (!EnvironmentUtils.isTesting()) { + loadDatabases(); + } } /**