Skip to content

test: Round 2 — 62 tests for Compress, HashAlgorithms, Download, Network, Strategy modules (closes #425)#426

Merged
JusterZhu merged 1 commit into
masterfrom
feature/core-unit-tests-round2
May 25, 2026
Merged

test: Round 2 — 62 tests for Compress, HashAlgorithms, Download, Network, Strategy modules (closes #425)#426
JusterZhu merged 1 commit into
masterfrom
feature/core-unit-tests-round2

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #424. Adds 62 tests across 5 remaining modules, bringing total CoreTest count to 600.

New Files (6 files)

Module File Tests
Compress CompressProviderTests.cs 4
ZipCompressionStrategyTests.cs 8
HashAlgorithms Sha256HashAlgorithmTests.cs 8
Download DownloadOrchestratorOptionsComplementaryTests.cs 4
Network VersionServiceAndAuthTests.cs 9
Strategy StrategyCreationTests.cs 26

Coverage

Compress (12 tests)

  • CompressProvider: zip/unknown format dispatch for Compress and Decompress
  • ZipCompressionStrategy: new directory, existing archive update, decompress (plain/nested paths/UTF-8 encoding/root directory flag), missing file handling

HashAlgorithms (8 tests)

  • FileNotFound → FileNotFoundException on both ComputeHash and ComputeHashBytes
  • Empty file, same/different content hash determinism
  • ComputeHashBytes returns correct 32-byte SHA256
  • Consistency across repeated calls
  • Large file (1MB) hash computation

Network (9 tests)

  • SSL policy: SetSslValidationPolicy null guard, StrictSslValidationPolicy (no errors/any error)
  • Auth factory: all 7 paths (Hmac priority, ApiKey scheme, Bearer default, NoOp fallback)

Strategy (26 tests)

  • ClientUpdateStrategy: Create(null guard/OS resolve), UseUpdatePrecheck (null guard/chain pattern), ExecuteAsync not-configured guard
  • UpgradeUpdateStrategy: Create(null guard/OS resolve), ExecuteAsync not-configured guard
  • OSSUpdateStrategy: Create Client/Upgrade roles, StartApp null-safe, IsOssUpgrade: 11 cases (null/empty/whitespace/client lower/equal/higher/invalid format)
  • AbstractStrategy.CheckPath: 5× null/empty inputs, file-exists/found-empty

Test Results

\
Passed: 600 | Failed: 0 | Total: 600
\\

Closes #425

…Network, Strategy modules

- Compress: 12 tests (CompressProvider zip/unknown formats, ZipCompressionStrategy compress/decompress/nested/utf8/rootDir)
- HashAlgorithms: 8 tests (Sha256HashAlgorithm ComputeHash/ComputeHashBytes, not-found/same-content/different/large file)
- Download: 4 tests (DownloadOrchestratorOptions From/negative timeout/retry, DownloadExecutor/Pipeline structure)
- Network: 9 tests (VersionService.SetSslValidationPolicy, StrictSsl/any error, HttpAuthProviderFactory 7 paths)
- Strategy: 26 tests (ClientUpdateStrategy/UpgradeUpdateStrategy/OSSUpdateStrategy Create/StartApp/UsePrecheck, CheckPath, IsOssUpgrade logic)

All 600 tests pass. Closes #425
Copilot AI review requested due to automatic review settings May 25, 2026 15:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands GeneralUpdate.Core test coverage by adding a second batch of unit tests targeting previously uncovered modules (Compress, HashAlgorithms, Download, Network, Strategy), continuing the test coverage plan from #424/#423 and closing #425.

Changes:

  • Add new xUnit test suites for compression (provider + zip strategy) and SHA256 hashing.
  • Add complementary coverage for DownloadOrchestratorOptions.From(...) sanitization behavior.
  • Add tests for network SSL validation policy + auth provider factory selection and strategy creation/guard behaviors.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/CoreTest/Strategy/StrategyCreationTests.cs Adds strategy creation/guard tests, plus CheckPath and OSS version comparison tests.
tests/CoreTest/Network/VersionServiceAndAuthTests.cs Adds SSL policy guard/behavior tests and HttpAuthProviderFactory selection tests.
tests/CoreTest/HashAlgorithms/Sha256HashAlgorithmTests.cs Adds file-based SHA256 tests for not-found, determinism, and byte-length.
tests/CoreTest/Download/DownloadOrchestratorOptionsComplementaryTests.cs Adds complementary tests for timeout defaulting and retry-count clamping.
tests/CoreTest/Compress/ZipCompressionStrategyTests.cs Adds zip compress/decompress tests including nested paths, UTF-8, and missing zip handling.
tests/CoreTest/Compress/CompressProviderTests.cs Adds dispatch/exception coverage for CompressProvider compress/decompress format selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +176 to +183
// Access protected static CheckPath via subclass
private static string InvokeCheckPath(AbstractStrategy strategy, string path, string name)
=> WindowsStrategy_CheckPath(path, name);

[System.Runtime.CompilerServices.MethodImpl(
System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static string WindowsStrategy_CheckPath(string path, string name)
{
Comment on lines +202 to +235
var result = CompareVersions(cv, sv);
Assert.False(result);
}

[Fact]
public void IsVersionUpgrade_ClientLower_ReturnsTrue()
{
Assert.True(CompareVersions("1.0.0", "2.0.0"));
Assert.True(CompareVersions("1.9.9", "2.0.0"));
}

[Fact]
public void IsVersionUpgrade_ClientEqualOrHigher_ReturnsFalse()
{
Assert.False(CompareVersions("2.0.0", "2.0.0"));
Assert.False(CompareVersions("3.0.0", "2.0.0"));
}

[Fact]
public void IsVersionUpgrade_InvalidFormat_ReturnsFalse()
{
Assert.False(CompareVersions("not.a.version", "2.0.0"));
Assert.False(CompareVersions("1.0.0", "not.a.version"));
Assert.False(CompareVersions("abc", "xyz"));
}

// Simulates OSSUpdateStrategy.IsOssUpgrade logic
private static bool CompareVersions(string clientVersion, string serverVersion)
{
if (string.IsNullOrWhiteSpace(clientVersion) || string.IsNullOrWhiteSpace(serverVersion))
return false;
return Version.TryParse(clientVersion, out var cv)
&& Version.TryParse(serverVersion, out var sv)
&& cv < sv;
Comment on lines +99 to +100
var ex = Record.Exception(() => _strategy.Decompress(nonexistent, destDir, Encoding.UTF8));
Assert.Null(ex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Round 2: Unit tests for Compress, HashAlgorithms, Download Executors, Network, Silent, and Strategy modules

2 participants