Skip to content

Commit

Permalink
Add simple test to check if changes to files are ingested correctly
Browse files Browse the repository at this point in the history
Test to cover #1924 fix
  • Loading branch information
Al12rs committed Aug 27, 2024
1 parent 1877a97 commit 3a5fcc7
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## 1 - Loadout Created (A) - Synced:
Added a new loadout and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (0) - Tx:100000000000008
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Current State - (0) - Tx:100000000000008
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Loadout A - (0)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |



## 2 - Added bin/newFile - Synced:
Added a new file to the game and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (1) - Tx:10000000000000B
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |
### Current State - (1) - Tx:10000000000000B
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |
### Loadout A - (1)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000003, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |



## 2 - Updated the file - Synced:
Updated the new file file and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (1) - Tx:10000000000000E
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |
### Current State - (1) - Tx:10000000000000E
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |
### Loadout A - (1)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000003, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |



Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Text;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Games.TestFramework;
using Xunit.Abstractions;

namespace NexusMods.DataModel.Synchronizer.Tests;

public class GeneralFileManagementTests (ITestOutputHelper helper) : ACyberpunkIsolatedGameTest<GeneralModManagementTests>(helper)
{
[Fact]
public async Task SynchronizerFileManagementTest()
{
var sb = new StringBuilder();

await Synchronizer.RescanGameFiles(GameInstallation);
var loadoutA = await CreateLoadout(false);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 1 - Loadout Created (A) - Synced",
"""
Added a new loadout and synced it.
""", [loadoutA]);

// Add a new file to the game
var newfileGamePath = new GamePath(LocationId.Game, "bin/newFile.txt");
var newFileFullPath = GameInstallation.LocationsRegister.GetResolvedPath(newfileGamePath);
newFileFullPath.Parent.CreateDirectory();
await newFileFullPath.WriteAllTextAsync("Hello World!");

await Synchronizer.RescanGameFiles(GameInstallation);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 2 - Added bin/newFile - Synced",
"""
Added a new file to the game and synced it.
""", [loadoutA]);

// Update the new file contents
await newFileFullPath.WriteAllTextAsync("Hello World! Updated!");

await Synchronizer.RescanGameFiles(GameInstallation);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 2 - Updated the file - Synced",
"""
Updated the new file file and synced it.
""", [loadoutA]);

await Verify(sb.ToString(), extension: "md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<None Update="GeneralModManagementTests.SynchronizerAddAndDisableMods.verified.md">
<DependentUpon>GeneralModManagementTests.cs</DependentUpon>
</None>
<None Update="GeneralFileManagementTests.SynchronizerFileManagementTest.verified.md">
<DependentUpon>GeneralFileManagementTests.cs</DependentUpon>
</None>
</ItemGroup>

</Project>

0 comments on commit 3a5fcc7

Please sign in to comment.