Skip to content

Commit

Permalink
Add a sanity check to the legacy database sanity checks (#2242)
Browse files Browse the repository at this point in the history
* Add a sanity check to the legacy database santiy checks

* Moved some namespaces, and didn't move all of them in the project

* More checks to try and figure out why this is breaking on Mac
  • Loading branch information
halgari authored Nov 11, 2024
1 parent c10bbcd commit 5269982
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,46 @@
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.FileExtractor;
using NexusMods.Abstractions.Loadouts;
using NexusMods.DataModel.Migrations;
using NexusMods.FileExtractor.FileSignatures;
using NexusMods.Hashing.xxHash3;
using NexusMods.MnemonicDB;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.ElementComparers;
using NexusMods.MnemonicDB.Storage;
using NexusMods.MnemonicDB.Storage.RocksDbBackend;
using NexusMods.Paths;
using Xunit;

namespace NexusMods.DataModel.Migrations.Tests;
namespace NexusMods.DataModel.SchemaVersions.Tests;

public class LegacyDatabaseSupportTests(IServiceProvider provider, TemporaryFileManager tempManager, IFileExtractor extractor)
{
private readonly SignatureChecker _zipSignatureChecker = new(FileType.ZIP);

[Theory]
[MemberData(nameof(DatabaseNames))]
public async Task TestDatabase(string name)
{
var path = DatabaseFolder().Combine(name);
path.FileExists.Should().BeTrue();

var path = DatabaseFolder().Combine(name);
path.FileExists.Should().BeTrue("the database file should exist");

await using (var stream = path.Read())
{
var isZip = await _zipSignatureChecker.MatchesAnyAsync(stream);
isZip.Should().BeTrue("the database file should be a ZIP archive, you may need to pull the file from LFS (`git lfs pull`)");
}

await using var workingFolder = tempManager.CreateFolder();
await extractor.ExtractAllAsync(path, workingFolder.Path);


var datamodelFolder = workingFolder.Path.Combine("MnemonicDB.rocksdb");
datamodelFolder.DirectoryExists().Should().BeTrue("the extracted database folder should exist");
datamodelFolder.EnumerateFiles().Should().NotBeEmpty("the extracted database folder should contain files");

using var backend = new Backend();
var settings = new DatomStoreSettings
{
Path = workingFolder.Path.Combine("MnemonicDB.rocksdb"),
Path = datamodelFolder,
};
using var datomStore = new DatomStore(provider.GetRequiredService<ILogger<DatomStore>>(), settings, backend);
var connection = new Connection(provider.GetRequiredService<ILogger<Connection>>(), datomStore, provider, provider.GetServices<IAnalyzer>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NexusMods.Hashing.xxHash3;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.DataModel.Migrations.Tests;
namespace NexusMods.DataModel.SchemaVersions.Tests;

public class SchemaFailsafes(IConnection connection)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/NexusMods.DataModel.SchemaVersions.Tests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NexusMods.App;
using NexusMods.Paths;

namespace NexusMods.DataModel.Migrations.Tests;
namespace NexusMods.DataModel.SchemaVersions.Tests;

public class Startup
{
Expand Down

0 comments on commit 5269982

Please sign in to comment.