diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java b/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java index 3c2d1b7b50..bfbb76b614 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java @@ -130,7 +130,7 @@ private int getSchemaVersion() { return getIntPragma("schema_version"); } - private int getUserVersion() { + public int getUserVersion() { return getIntPragma("user_version"); } diff --git a/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java b/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java index 18d4ae5b6a..c0229272b8 100644 --- a/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java +++ b/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java @@ -19,9 +19,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; +import java.util.Comparator; import java.util.List; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.photonvision.common.util.TestUtils; import org.photonvision.vision.camera.CameraType; @@ -30,14 +36,40 @@ import org.photonvision.vision.pipeline.ReflectivePipelineSettings; public class SQLConfigTest { + private static Path tmpDir; + @BeforeAll public static void init() { TestUtils.loadLibraries(); + try { + tmpDir = Files.createTempDirectory("SQLConfigTest"); + } catch (IOException e) { + System.out.println("Couldn't create temporary directory, using current directory"); + tmpDir = Path.of("jdbc_test", "temp"); + } + } + + @AfterAll + public static void cleanUp() throws IOException { + Files.walk(tmpDir).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } + + @Test + @Order(1) + public void testMigration() { + SqlConfigProvider cfgLoader = new SqlConfigProvider(tmpDir); + cfgLoader.load(); + + assertEquals( + DatabaseSchema.migrations.length, + cfgLoader.getUserVersion(), + "Database isn't at the correct version"); } @Test + @Order(2) public void testLoad() { - var cfgLoader = new SqlConfigProvider(Path.of("jdbc_test")); + var cfgLoader = new SqlConfigProvider(tmpDir); cfgLoader.load();