test(net): exercise UpdateChecker.CheckAsync end-to-end via a stub transport
CheckAsync built its own HttpClient inline, so nothing beyond tag parsing was testable without hitting the real GitHub API. Added an internal CheckAsync(currentVersion, HttpMessageHandler, ct) overload (the public method now delegates to it) as a seam for a stub handler, and tests for the full best-effort matrix: newer/equal/older/unparseable tag, missing html_url, HTTP error status, malformed JSON, a thrown HttpRequestException, and an unparseable local version — all of which must resolve to null or the correct LatestRelease, never throw.
This commit is contained in:
@@ -28,11 +28,19 @@ public static class UpdateChecker
|
||||
public string? HtmlUrl { get; set; }
|
||||
}
|
||||
|
||||
public static async Task<LatestRelease?> CheckAsync(string currentVersion, CancellationToken ct = default)
|
||||
public static Task<LatestRelease?> CheckAsync(string currentVersion, CancellationToken ct = default) =>
|
||||
CheckAsync(currentVersion, handler: null, ct);
|
||||
|
||||
/// <summary>Test seam: <paramref name="handler"/> replaces the real HTTP transport.</summary>
|
||||
internal static async Task<LatestRelease?> CheckAsync(string currentVersion,
|
||||
HttpMessageHandler? handler, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
|
||||
using var http = handler is null
|
||||
? new HttpClient()
|
||||
: new HttpClient(handler, disposeHandler: false);
|
||||
http.Timeout = TimeSpan.FromSeconds(10);
|
||||
http.DefaultRequestHeaders.UserAgent.ParseAdd("PalladiumWallet");
|
||||
using var response = await http.GetAsync(ReleasesApiUrl, ct).ConfigureAwait(false);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
Reference in New Issue
Block a user