2020-05-13 03:04:32 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Server.Services;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Test
|
|
|
|
|
{
|
|
|
|
|
public class ArchiveMaintainerTests : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public ArchiveMaintainerTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanIngestFiles()
|
|
|
|
|
{
|
|
|
|
|
var maintainer = Fixture.GetService<ArchiveMaintainer>();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using var tf = new TempFile();
|
|
|
|
|
await using var tf2 = new TempFile();
|
2020-05-13 03:04:32 +00:00
|
|
|
|
|
|
|
|
|
await tf.Path.WriteAllBytesAsync(RandomData(1024));
|
|
|
|
|
await tf.Path.CopyToAsync(tf2.Path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hash = await tf.Path.FileHashAsync();
|
|
|
|
|
await maintainer.Ingest(tf.Path);
|
|
|
|
|
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Assert.NotNull(hash);
|
|
|
|
|
|
|
|
|
|
Assert.True(maintainer.TryGetPath(hash!.Value, out var found));
|
2020-05-13 03:04:32 +00:00
|
|
|
|
Assert.Equal(await tf2.Path.ReadAllBytesAsync(), await found.ReadAllBytesAsync());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task IngestsExistingFiles()
|
|
|
|
|
{
|
|
|
|
|
var maintainer = Fixture.GetService<ArchiveMaintainer>();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using var tf = new TempFile();
|
2020-05-13 03:04:32 +00:00
|
|
|
|
|
|
|
|
|
await tf.Path.WriteAllBytesAsync(RandomData(1024));
|
|
|
|
|
var hash = await tf.Path.FileHashAsync();
|
|
|
|
|
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Assert.NotNull(hash);
|
|
|
|
|
|
|
|
|
|
await tf.Path.CopyToAsync(Fixture.ServerArchivesFolder.Combine(hash!.Value.ToHex()));
|
2020-05-13 03:04:32 +00:00
|
|
|
|
maintainer.Start();
|
|
|
|
|
|
2021-01-09 18:53:44 +00:00
|
|
|
|
Assert.True(maintainer.TryGetPath(hash!.Value, out var found));
|
2020-05-13 03:04:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|