Skip to content

Commit

Permalink
Added unit test for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
crschardt committed Dec 26, 2023
1 parent 0766f7d commit 7aacb66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private int getSchemaVersion() {
return getIntPragma("schema_version");
}

private int getUserVersion() {
public int getUserVersion() {
return getIntPragma("user_version");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit 7aacb66

Please sign in to comment.