Skip to content

Commit

Permalink
Test MigrationService data directory version detection
Browse files Browse the repository at this point in the history
- Test with data directory before MigrationService was introduced
- Test with invalid data directory version
- Test with valid data directory version
  • Loading branch information
alvasw committed Oct 20, 2024
1 parent 27f1a6a commit 9d8187d
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package bisq.application.migration;

import bisq.common.platform.InvalidVersionException;
import bisq.common.platform.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class MigrationServiceTests {
@Test
void getDataDirVersionBeforeMigrationServiceIntroduced(@TempDir Path dataDir) {
MigrationService migrationService = new MigrationService(dataDir);
Version dataDirVersion = migrationService.getDataDirVersion();
assertThat(dataDirVersion)
.isEqualTo(MigrationService.VERSION_BEFORE_MIGRATION_SERVICE_INTRODUCED);
}

@Test
void getDataDirInvalidVersion(@TempDir Path dataDir) throws IOException {
Path versionFilePath = dataDir.resolve("version");
Files.writeString(versionFilePath, "2.1-alpha");

MigrationService migrationService = new MigrationService(dataDir);
assertThrows(InvalidVersionException.class, migrationService::getDataDirVersion);
}

@Test
void getDataDirVersion(@TempDir Path dataDir) throws IOException {
Path versionFilePath = dataDir.resolve("version");
Files.writeString(versionFilePath, "2.1.34");

MigrationService migrationService = new MigrationService(dataDir);
Version dataDirVersion = migrationService.getDataDirVersion();
assertThat(dataDirVersion)
.isEqualTo(new Version("2.1.34"));
}
}

0 comments on commit 9d8187d

Please sign in to comment.