2020-05-13 03:39:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-08-13 04:14:35 +00:00
|
|
|
|
using Dapper;
|
2020-05-13 03:39:03 +00:00
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
using Wabbajack.Lib.ModListRegistry;
|
|
|
|
|
using Wabbajack.Server.DataLayer;
|
2020-05-13 21:52:34 +00:00
|
|
|
|
using Wabbajack.Server.DTOs;
|
2020-05-13 03:39:03 +00:00
|
|
|
|
using Wabbajack.Server.Services;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Test
|
|
|
|
|
{
|
|
|
|
|
public class ModListValidationTests : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public ModListValidationTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanLoadMetadataFromTestServer()
|
|
|
|
|
{
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var modlist = await MakeModList("CanLoadMetadataFromTestServer.txt");
|
2020-05-13 03:39:03 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modlist.ToString();
|
|
|
|
|
var data = await ModlistMetadata.LoadFromGithub();
|
2020-05-13 13:45:32 +00:00
|
|
|
|
Assert.Equal(2, data.Count);
|
2020-05-13 03:39:03 +00:00
|
|
|
|
Assert.Equal("test_list", data.First().Links.MachineURL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanIngestModLists()
|
|
|
|
|
{
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var modlist = await MakeModList("CanIngestModLists.txt");
|
2020-05-13 03:39:03 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modlist.ToString();
|
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
|
|
|
|
var downloader = Fixture.GetService<ModListDownloader>();
|
2021-02-04 03:48:30 +00:00
|
|
|
|
await downloader.Execute();
|
2020-05-13 03:39:03 +00:00
|
|
|
|
|
|
|
|
|
foreach (var list in ModListMetaData)
|
|
|
|
|
{
|
|
|
|
|
Assert.True(await sql.HaveIndexedModlist(list.Links.MachineURL, list.DownloadMetadata.Hash));
|
|
|
|
|
}
|
2020-05-13 12:09:20 +00:00
|
|
|
|
|
|
|
|
|
// Nothing has changed so we shouldn't be downloading anything this time
|
2021-02-04 03:48:30 +00:00
|
|
|
|
Assert.Equal(0, await downloader.Execute());
|
2020-05-13 12:09:20 +00:00
|
|
|
|
|
2020-05-13 03:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 21:52:34 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanValidateModLists()
|
|
|
|
|
{
|
2020-08-13 04:14:35 +00:00
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
|
|
|
|
await using var conn = await sql.Open();
|
|
|
|
|
await conn.ExecuteAsync("DELETE from Patches");
|
|
|
|
|
|
2020-05-22 04:21:32 +00:00
|
|
|
|
var modlists = await MakeModList("CanValidateModlistsFile.txt");
|
2020-05-13 21:52:34 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modlists.ToString();
|
|
|
|
|
Utils.Log("Updating modlists");
|
|
|
|
|
await RevalidateLists(true);
|
|
|
|
|
|
|
|
|
|
Utils.Log("Checking validated results");
|
|
|
|
|
var data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
await CheckListFeeds(0, 1);
|
|
|
|
|
|
|
|
|
|
Utils.Log("Break List");
|
2020-05-22 04:21:32 +00:00
|
|
|
|
var archive = "CanValidateModlistsFile.txt".RelativeTo(Fixture.ServerPublicFolder);
|
2020-05-13 21:52:34 +00:00
|
|
|
|
await archive.MoveToAsync(archive.WithExtension(new Extension(".moved")), true);
|
|
|
|
|
|
|
|
|
|
// We can revalidate but the non-nexus archives won't be checked yet since the list didn't change
|
|
|
|
|
await RevalidateLists(false);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
// Run the non-nexus validator
|
|
|
|
|
await RevalidateLists(true);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
await CheckListFeeds(1, 0);
|
|
|
|
|
|
|
|
|
|
Utils.Log("Fix List");
|
|
|
|
|
await archive.WithExtension(new Extension(".moved")).MoveToAsync(archive, false);
|
|
|
|
|
|
|
|
|
|
await RevalidateLists(true);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
await CheckListFeeds(0, 1);
|
|
|
|
|
|
2020-05-20 21:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanHealLists()
|
|
|
|
|
{
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var modlists = await MakeModList("CanHealLists.txt");
|
2020-05-20 21:48:26 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modlists.ToString();
|
|
|
|
|
Utils.Log("Updating modlists");
|
|
|
|
|
await RevalidateLists(true);
|
|
|
|
|
|
|
|
|
|
Utils.Log("Checking validated results");
|
|
|
|
|
var data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
await CheckListFeeds(0, 1);
|
|
|
|
|
|
|
|
|
|
Utils.Log("Break List by changing the file");
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var archive = "CanHealLists.txt".RelativeTo(Fixture.ServerPublicFolder);
|
2020-05-20 21:48:26 +00:00
|
|
|
|
await archive.WriteAllTextAsync("broken");
|
|
|
|
|
|
|
|
|
|
// We can revalidate but the non-nexus archives won't be checked yet since the list didn't change
|
|
|
|
|
await RevalidateLists(false);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
|
|
|
|
|
// Run the non-nexus validator
|
|
|
|
|
await RevalidateLists(true);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Passed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Updating);
|
|
|
|
|
|
|
|
|
|
var patcher = Fixture.GetService<PatchBuilder>();
|
2020-05-26 04:48:37 +00:00
|
|
|
|
Assert.True(await patcher.Execute() > 1);
|
2020-05-20 21:48:26 +00:00
|
|
|
|
|
|
|
|
|
await RevalidateLists(false);
|
|
|
|
|
|
|
|
|
|
data = (await ModlistMetadata.LoadFromGithub()).FirstOrDefault(l => l.Links.MachineURL == "test_list");
|
|
|
|
|
Assert.NotNull(data);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Failed);
|
|
|
|
|
Assert.Equal(1, data.ValidationSummary.Passed);
|
|
|
|
|
Assert.Equal(0, data.ValidationSummary.Updating);
|
2020-05-13 21:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task RevalidateLists(bool runNonNexus)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var downloader = Fixture.GetService<ModListDownloader>();
|
2021-02-04 03:48:30 +00:00
|
|
|
|
await downloader.Execute();
|
2020-05-13 21:52:34 +00:00
|
|
|
|
|
|
|
|
|
if (runNonNexus)
|
|
|
|
|
{
|
|
|
|
|
var nonNexus = Fixture.GetService<NonNexusDownloadValidator>();
|
|
|
|
|
await nonNexus.Execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var validator = Fixture.GetService<ListValidator>();
|
|
|
|
|
await validator.Execute();
|
2020-05-20 21:48:26 +00:00
|
|
|
|
|
|
|
|
|
var archiver = Fixture.GetService<ArchiveDownloader>();
|
|
|
|
|
await archiver.Execute();
|
2020-05-13 21:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CheckListFeeds(int failed, int passed)
|
|
|
|
|
{
|
|
|
|
|
var statusJson = await _client.GetJsonAsync<DetailedStatus>(MakeURL("lists/status/test_list.json"));
|
|
|
|
|
Assert.Equal(failed, statusJson.Archives.Count(a => a.IsFailing));
|
|
|
|
|
Assert.Equal(passed, statusJson.Archives.Count(a => !a.IsFailing));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var statusHtml = await _client.GetHtmlAsync(MakeURL("lists/status/test_list.html"));
|
|
|
|
|
Assert.NotEmpty(statusHtml.DocumentNode.Descendants().Where(n => n.InnerHtml == $"Failed ({failed}):"));
|
|
|
|
|
Assert.NotEmpty(statusHtml.DocumentNode.Descendants().Where(n => n.InnerHtml == $"Passed ({passed}):"));
|
|
|
|
|
|
|
|
|
|
var statusRss = await _client.GetHtmlAsync(MakeURL("lists/status/test_list/broken.rss"));
|
|
|
|
|
Assert.Equal(failed, statusRss.DocumentNode.SelectNodes("//item")?.Count ?? 0);
|
2020-11-19 22:56:30 +00:00
|
|
|
|
|
|
|
|
|
var heartBeat = await _client.GetHtmlAsync(MakeURL("heartbeat/report"));
|
|
|
|
|
Assert.Contains(heartBeat.DocumentNode.Descendants(), c => c.InnerText.StartsWith("test_list"));
|
2020-05-13 21:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-13 03:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|