Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Unit Tests to Pass on PR Submissions from Forked Repos #2678

Merged
merged 15 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ jobs:
with:
dotnet-version: '9.0.x'
include-prerelease: true


- name: Test
if: ${{ github.ref == 'refs/heads/main' }}
run: dotnet test /p:EnableWindowsTargeting=true

- name: Test
run: dotnet test /p:EnableWindowsTargeting=true --filter "Category!=FlakeyNetwork"
if: ${{ github.ref != 'refs/heads/main' }}
run: dotnet test /p:EnableWindowsTargeting=true --filter "Category!=RequiresOAuth"

#- name: Upload Test Folder on Failure
# if: ${{ failure() }}
Expand Down
45 changes: 0 additions & 45 deletions Wabbajack.Downloaders.Dispatcher.Test/DownloaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,51 +219,6 @@ public DownloaderTests(DownloadDispatcher dispatcher, TemporaryFileManager temp)
*/
};

private bool AutoPassTest(Archive archive)
{
return false;
}

[Theory]
[Trait("Category", "FlakeyNetwork")]
[MemberData(nameof(TestStates))]
public async Task TestDownloadingFile(Archive archive, Archive badArchive)
{
if (AutoPassTest(archive)) return;
await using var tempFile = _temp.CreateFile();
var hash = await _dispatcher.Download(archive, tempFile.Path, CancellationToken.None);
Assert.Equal(archive.Hash, hash);
}

[Theory]
[Trait("Category", "FlakeyNetwork")]
[MemberData(nameof(TestStates))]
public async Task TestFileVerification(Archive goodArchive, Archive badArchive)
{
if (AutoPassTest(goodArchive)) return;
Assert.True(await _dispatcher.Verify(goodArchive, CancellationToken.None));
Assert.False(await _dispatcher.Verify(badArchive, CancellationToken.None));
}

[Theory]
[Trait("Category", "FlakeyNetwork")]
[MemberData(nameof(TestStates))]
public async Task CanParseAndUnParseUrls(Archive goodArchive, Archive badArchive)
{
if (AutoPassTest(goodArchive)) return;
var downloader = _dispatcher.Downloader(goodArchive);
if (downloader is IUrlDownloader urlDownloader)
{
var unparsed = urlDownloader.UnParse(goodArchive.State);

var parsed = urlDownloader.Parse(unparsed);
Assert.NotNull(parsed);

Assert.Equal(goodArchive.State.GetType(), parsed.GetType());
Assert.True(await _dispatcher.Verify(new Archive {State = parsed, Hash = goodArchive.Hash}, CancellationToken.None));
}
}

[Theory]
[MemberData(nameof(TestStates))]
public async Task CanParseAndUnParseMetaInis(Archive goodArchive, Archive badArchive)
Expand Down
4 changes: 4 additions & 0 deletions Wabbajack.Installer.Test/StandardInstallerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Xunit;
Expand Down Expand Up @@ -52,6 +53,9 @@ public async Task CanInstallAList()
VideoMemorySize = 8L * 1024 * 1024 * 1024
};

var configuration = _provider.GetService<Client>();
configuration.IgnoreMirrorList = true;

var installer = _provider.GetService<StandardInstaller>();
Assert.True(await installer.Begin(CancellationToken.None));

Expand Down
2 changes: 2 additions & 0 deletions Wabbajack.Networking.NexusApi.Test/NexusApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public NexusApiTests(NexusApi api)
}

[Fact]
[Trait("Category", "RequiresOAuth")]
public async Task CanValidateUser()
{
var (info, headers) = await _api.Validate();
Assert.True(info.IsPremium);
}

[Fact]
[Trait("Category", "RequiresOAuth")]
public async Task CanGetModInfo()
{
var (_, originalHeaders) = await _api.Validate();
Expand Down
4 changes: 4 additions & 0 deletions Wabbajack.Networking.WabbajackClientApi/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class Client
private readonly ITokenProvider<WabbajackApiState> _token;
private bool _inited;

public bool IgnoreMirrorList { get; set; } = false;

public Client(ILogger<Client> logger, HttpClient client, ITokenProvider<WabbajackApiState> token,
DTOSerializer dtos,
Expand Down Expand Up @@ -108,6 +109,9 @@ public async Task<ServerAllowList> LoadDownloadAllowList()

public async Task<Archive[]> LoadMirrors()
{
if (IgnoreMirrorList)
return Array.Empty<Archive>();

var str = await _client.GetStringAsync(_configuration.MirrorList);
return JsonSerializer.Deserialize<Archive[]>(str, _dtos.Options) ?? [];
}
Expand Down
Loading