2020-04-09 12:46:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-04-10 03:54:02 +00:00
|
|
|
|
using Dapper;
|
2020-04-09 12:46:33 +00:00
|
|
|
|
using Wabbajack.BuildServer.Model.Models;
|
|
|
|
|
using Wabbajack.BuildServer.Models.JobQueue;
|
|
|
|
|
using Wabbajack.BuildServer.Models.Jobs;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
|
|
|
|
using Wabbajack.VirtualFileSystem;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
using Xunit.Priority;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Test
|
|
|
|
|
{
|
|
|
|
|
public class ModlistUpdater : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public ModlistUpdater(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact, Priority(0)]
|
2020-04-10 03:54:02 +00:00
|
|
|
|
public async Task CanIndexAndUpdateFiles()
|
2020-04-09 12:46:33 +00:00
|
|
|
|
{
|
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
|
|
|
|
var modId = long.MaxValue >> 1;
|
|
|
|
|
var oldFileId = long.MaxValue >> 2;
|
|
|
|
|
var newFileId = (long.MaxValue >> 2) + 1;
|
|
|
|
|
|
|
|
|
|
var oldFileData = RandomData();
|
|
|
|
|
var newFileData = RandomData();
|
|
|
|
|
var oldDataHash = oldFileData.xxHash();
|
|
|
|
|
var newDataHash = newFileData.xxHash();
|
|
|
|
|
|
|
|
|
|
await "old_file_data.random".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(oldFileData);
|
|
|
|
|
await "new_file_data.random".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(newFileData);
|
|
|
|
|
|
|
|
|
|
await sql.EnqueueJob(new Job
|
|
|
|
|
{
|
|
|
|
|
Payload = new IndexJob
|
|
|
|
|
{
|
|
|
|
|
Archive = new Archive
|
|
|
|
|
{
|
|
|
|
|
Name = "Oldfile",
|
2020-04-09 20:20:34 +00:00
|
|
|
|
State = new HTTPDownloader.State(MakeURL("old_file_data.random"))
|
2020-04-09 12:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await sql.EnqueueJob(new Job
|
|
|
|
|
{
|
|
|
|
|
Payload = new IndexJob
|
|
|
|
|
{
|
|
|
|
|
Archive = new Archive
|
|
|
|
|
{
|
|
|
|
|
Name = "Newfile",
|
2020-04-09 20:20:34 +00:00
|
|
|
|
State = new HTTPDownloader.State(MakeURL("new_file_data.random"))
|
2020-04-09 12:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await RunAllJobs();
|
|
|
|
|
|
|
|
|
|
Assert.True(await sql.HaveIndexdFile(oldDataHash));
|
|
|
|
|
Assert.True(await sql.HaveIndexdFile(newDataHash));
|
|
|
|
|
|
|
|
|
|
var settings = Fixture.GetService<AppSettings>();
|
|
|
|
|
Assert.Equal($"Oldfile_{oldDataHash.ToHex()}_".RelativeTo(Fixture.ServerArchivesFolder), settings.PathForArchive(oldDataHash));
|
|
|
|
|
Assert.Equal($"Newfile_{newDataHash.ToHex()}_".RelativeTo(Fixture.ServerArchivesFolder), settings.PathForArchive(newDataHash));
|
|
|
|
|
|
2020-04-10 03:54:02 +00:00
|
|
|
|
Utils.Log($"Download Updating {oldDataHash} -> {newDataHash}");
|
|
|
|
|
await using var conn = await sql.Open();
|
|
|
|
|
|
|
|
|
|
await conn.ExecuteAsync("DELETE FROM dbo.DownloadStates WHERE Hash in (@OldHash, @NewHash);",
|
|
|
|
|
new {OldHash = (long)oldDataHash, NewHash = (long)newDataHash});
|
|
|
|
|
|
|
|
|
|
await sql.AddDownloadState(oldDataHash, new NexusDownloader.State
|
|
|
|
|
{
|
|
|
|
|
Game = Game.Oblivion,
|
|
|
|
|
ModID = modId,
|
|
|
|
|
FileID = oldFileId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await sql.AddDownloadState(newDataHash, new NexusDownloader.State
|
|
|
|
|
{
|
|
|
|
|
Game = Game.Oblivion,
|
|
|
|
|
ModID = modId,
|
|
|
|
|
FileID = newFileId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(await sql.GetNexusStateByHash(oldDataHash));
|
|
|
|
|
Assert.NotNull(await sql.GetNexusStateByHash(newDataHash));
|
|
|
|
|
|
|
|
|
|
// No nexus info, so no upgrade
|
|
|
|
|
var noUpgrade = await ClientAPI.GetModUpgrade(oldDataHash);
|
|
|
|
|
Assert.Null(noUpgrade);
|
|
|
|
|
|
|
|
|
|
// Add Nexus info
|
|
|
|
|
await sql.AddNexusModFiles(Game.Oblivion, modId, DateTime.Now,
|
|
|
|
|
new NexusApiClient.GetModFilesResponse
|
|
|
|
|
{
|
|
|
|
|
files = new List<NexusFileInfo>
|
|
|
|
|
{
|
|
|
|
|
new NexusFileInfo {category_name = "MAIN", file_id = newFileId, file_name = "New File"},
|
|
|
|
|
new NexusFileInfo {category_name = null, file_id = oldFileId, file_name = "Old File"}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var enqueuedUpgrade = await ClientAPI.GetModUpgrade(oldDataHash);
|
|
|
|
|
|
|
|
|
|
// Not Null because upgrade was enqueued
|
|
|
|
|
Assert.NotNull(enqueuedUpgrade);
|
|
|
|
|
|
|
|
|
|
await RunAllJobs();
|
|
|
|
|
|
|
|
|
|
Assert.True($"{oldDataHash.ToHex()}_{newDataHash.ToHex()}".RelativeTo(Fixture.ServerUpdatesFolder).IsFile);
|
2020-04-09 12:46:33 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|