wabbajack/Wabbajack.VFS.Test/HashCacheTest.cs

41 lines
1.2 KiB
C#
Raw Permalink Normal View History

2021-09-27 12:42:46 +00:00
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths.IO;
using Xunit;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.VFS.Test;
public class HashCacheTest
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
private readonly FileHashCache _cache;
private readonly TemporaryFileManager _manager;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public HashCacheTest(FileHashCache cache, TemporaryFileManager manager)
{
_cache = cache;
_manager = manager;
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
[Fact]
public async Task CanCacheAndPurgeHashes()
{
var testFile = _manager.CreateFile();
await testFile.Path.WriteAllTextAsync("Cheese for Everyone!");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="),
await _cache.FileHashCachedAsync(testFile.Path, CancellationToken.None));
2022-10-01 05:21:58 +00:00
Assert.True(await _cache.TryGetHashCache(testFile.Path) != default);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
_cache.Purge(testFile.Path);
2022-10-01 05:21:58 +00:00
var hash = await testFile.Path.Hash(CancellationToken.None);
Assert.NotEqual(hash, default);
Assert.NotEqual(hash, await _cache.TryGetHashCache(testFile.Path));
2021-10-23 16:51:17 +00:00
Assert.Equal(hash, await _cache.FileHashCachedAsync(testFile.Path, CancellationToken.None));
2021-09-27 12:42:46 +00:00
2022-10-01 05:21:58 +00:00
Assert.Equal(hash, await _cache.TryGetHashCache(testFile.Path));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
_cache.VacuumDatabase();
2021-09-27 12:42:46 +00:00
}
}