wabbajack/Wabbajack.BuildServer.Test/IndexedFilesTests.cs

95 lines
3.1 KiB
C#
Raw Normal View History

2020-03-31 22:05:36 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.BuildServer.Model.Models;
using Wabbajack.BuildServer.Models.Jobs;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.FileUploader;
using Xunit;
using Xunit.Abstractions;
using Xunit.Priority;
namespace Wabbajack.BuildServer.Test
{
[Collection("ServerTests")]
2020-03-31 22:05:36 +00:00
public class IndexedFilesTests : ABuildServerSystemTest
{
[Fact, Priority(1)]
public async Task CanIngestExportedInis()
{
2020-04-08 11:26:54 +00:00
var sql = Fixture.GetService<SqlService>();
2020-03-31 22:05:36 +00:00
var to = Fixture.ServerTempFolder.Combine("IniIngest");
await @"sql\DownloadStates".RelativeTo(AbsolutePath.EntryPoint).CopyDirectoryToAsync(to);
var result = await _authedClient.GetStringAsync(MakeURL("indexed_files/ingest/IniIngest"));
Assert.Equal("5", result);
2020-04-08 11:26:54 +00:00
await ClearJobQueue();
2020-03-31 22:05:36 +00:00
}
[Fact, Priority(2)]
public async Task CanQueryViaHash()
{
var hashes = new HashSet<Hash>
{
Hash.FromHex("097ad17ef4b9f5b7"),
Hash.FromHex("96fb53c3dc6397d2"),
Hash.FromHex("97a6d27b7becba19")
};
foreach (var hash in hashes)
{
Utils.Log($"Testing Archive {hash}");
var ini = await ClientAPI.GetModIni(hash);
Assert.NotNull(ini);
Assert.NotNull(DownloadDispatcher.ResolveArchive(ini.LoadIniString()));
}
}
[Fact]
public async Task CanNotifyOfInis()
{
2020-04-03 03:57:59 +00:00
var archive =
2020-04-10 01:29:53 +00:00
new Archive(
new NexusDownloader.State
2020-04-03 03:57:59 +00:00
{
Game = Game.SkyrimSpecialEdition,
ModID = long.MaxValue >> 3,
FileID = long.MaxValue >> 3,
2020-04-10 01:29:53 +00:00
})
{
2020-03-31 22:05:36 +00:00
Name = Guid.NewGuid().ToString()
2020-04-03 03:57:59 +00:00
};
Assert.True(await AuthorAPI.UploadPackagedInis(new[] {archive}));
2020-03-31 22:05:36 +00:00
var SQL = Fixture.GetService<SqlService>();
var job = await SQL.GetJob();
2020-04-03 03:57:59 +00:00
Assert.NotNull(job);
2020-03-31 22:05:36 +00:00
Assert.IsType<IndexJob>(job.Payload);
var payload = (IndexJob)job.Payload;
Assert.IsType<NexusDownloader.State>(payload.Archive.State);
var casted = (NexusDownloader.State)payload.Archive.State;
2020-04-03 03:57:59 +00:00
Assert.Equal(Game.SkyrimSpecialEdition, casted.Game);
2020-03-31 22:05:36 +00:00
// Insert the record into SQL
await SQL.AddDownloadState(Hash.FromHex("00e8bbbf591f61a3"), casted);
// Enqueue the same file again
2020-04-03 03:57:59 +00:00
Assert.True(await AuthorAPI.UploadPackagedInis(new[] {archive}));
2020-03-31 22:05:36 +00:00
// File is aleady indexed so nothing gets enqueued
Assert.Null(await SQL.GetJob());
}
public IndexedFilesTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
{
}
2020-03-31 22:05:36 +00:00
}
}