Nest snapshot test dbs in a root temp folder

Allows us to clean it all up easily.

Closes #558.
This commit is contained in:
Octavia Togami 2020-03-22 01:12:20 -07:00
parent b4d2db3dee
commit e6d5950b59
No known key found for this signature in database
GPG Key ID: CC364524D1983C99

View File

@ -31,6 +31,7 @@
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.storage.ChunkStoreHelper;
import com.sk89q.worldedit.world.storage.McRegionReader;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DynamicNode;
@ -76,6 +77,8 @@ class FileSystemSnapshotDatabaseTest {
.atZone(ZoneId.systemDefault());
static final ZonedDateTime TIME_TWO = TIME_ONE.minusDays(1);
private static Path TEMP_DIR;
@BeforeAll
static void setUpStatic() throws IOException, DataException {
try (InputStream in = Resources.getResource("world_region.mca.gzip").openStream();
@ -104,10 +107,17 @@ static void setUpStatic() throws IOException, DataException {
} finally {
reader.close();
}
TEMP_DIR = Files.createTempDirectory("worldedit-fs-snap-dbs");
}
@AfterAll
static void afterAll() throws IOException {
deleteTree(TEMP_DIR);
}
private static Path newTempDb() throws IOException {
return Files.createTempDirectory("worldedit-fs-snap-db");
return Files.createTempDirectory(TEMP_DIR, "db");
}
private static void deleteTree(Path root) throws IOException {
@ -175,7 +185,6 @@ private static Stream<? extends DynamicNode> getTests(ArchiveNioSupport nioSuppo
try {
Path dbRoot = root.resolve("snapshots");
Files.createDirectories(dbRoot);
// we leak `root` here, but I can't see a good way to clean it up.
return type.getNamedTests(new FSSDContext(nioSupport, dbRoot));
} catch (Throwable t) {
deleteTree(root);