Skip to content

Add comprehensive test suite for GeneralUpdate.Drivelution#140

Merged
JusterZhu merged 3 commits intodriverfrom
copilot/sub-pr-138
Feb 8, 2026
Merged

Add comprehensive test suite for GeneralUpdate.Drivelution#140
JusterZhu merged 3 commits intodriverfrom
copilot/sub-pr-138

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Implemented 110 unit tests covering the core driver update functionality introduced in GeneralUpdate.Drivelution.

Test Coverage

  • Core (15 tests): DriverUpdaterFactory platform detection, validator/backup factory methods, custom logger/config support
  • Utilities (68 tests):
    • HashValidator: SHA256/MD5 computation, file validation, cancellation
    • CompatibilityChecker: OS/architecture compatibility, platform detection
    • VersionComparer: SemVer 2.0 compliance including prerelease handling
    • RestartHelper: Restart mode validation
  • Models (18 tests): DriverInfo, UpdateStrategy, UpdateResult, ErrorInfo structure validation
  • Entry Point (9 tests): GeneralDrivelution factory methods, quick update flows, validation

Test Project Structure

src/c#/DrivelutionTest/
├── Core/
│   └── DriverUpdaterFactoryTests.cs
├── Utilities/
│   ├── HashValidatorTests.cs
│   ├── CompatibilityCheckerTests.cs
│   └── VersionComparerAndRestartHelperTests.cs
├── Models/
│   └── ModelTests.cs
└── GeneralDrivelutionTests.cs

Follows existing repository conventions: xUnit framework, .NET 8.0 target, Moq for mocking.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@JusterZhu JusterZhu linked an issue Feb 8, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits February 8, 2026 17:03
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GeneralUpdate.Drivelution Add comprehensive test suite for GeneralUpdate.Drivelution Feb 8, 2026
Copilot AI requested a review from JusterZhu February 8, 2026 17:07
@JusterZhu JusterZhu marked this pull request as ready for review February 8, 2026 17:07
Copilot AI review requested due to automatic review settings February 8, 2026 17:07
@JusterZhu JusterZhu merged commit 24782be into driver Feb 8, 2026
2 checks passed
@JusterZhu JusterZhu deleted the copilot/sub-pr-138 branch February 8, 2026 17:07
Copy link
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

Adds a new DrivelutionTest test project to exercise the GeneralUpdate.Drivelution library’s core utilities, models, and entry-point/factory behaviors.

Changes:

  • Introduces src/c#/DrivelutionTest xUnit test project referencing GeneralUpdate.Drivelution.
  • Adds unit tests for core utilities (hashing, compatibility, semver comparison, restart helper).
  • Adds validation tests for key models and basic GeneralDrivelution / DriverUpdaterFactory flows.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/c#/DrivelutionTest/Utilities/VersionComparerAndRestartHelperTests.cs Adds tests for SemVer comparisons and restart helper behavior.
src/c#/DrivelutionTest/Utilities/HashValidatorTests.cs Adds tests for file/string hashing, validation, and cancellation.
src/c#/DrivelutionTest/Utilities/CompatibilityCheckerTests.cs Adds tests for OS/arch detection and compatibility report logic.
src/c#/DrivelutionTest/Models/ModelTests.cs Adds default-value and property/enum tests for Drivelution models.
src/c#/DrivelutionTest/GeneralDrivelutionTests.cs Adds tests for entry-point creation, platform info, and “quick update/validate” flows.
src/c#/DrivelutionTest/DrivelutionTest.csproj Adds a new test project targeting net8.0 with xUnit/Moq packages and project reference.
src/c#/DrivelutionTest/Core/DriverUpdaterFactoryTests.cs Adds tests for factory creation/platform detection and validator/backup factories.

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

Comment on lines +24 to +26
<ItemGroup>
<ProjectReference Include="..\GeneralUpdate.Drivelution\GeneralUpdate.Drivelution.csproj" />
</ItemGroup>
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

This new test project isn’t referenced by src/c#/GeneralUpdate.sln (no DrivelutionTest entry), so a solution-level dotnet test run won’t execute these tests. Add the project to the solution (or update the test/CI invocation to include this csproj explicitly) so coverage is actually exercised.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +26
[Fact]
public void Create_WithoutParameters_ReturnsNonNullInstance()
{
// Arrange & Act
var updater = DriverUpdaterFactory.Create();

// Assert
Assert.NotNull(updater);
Assert.IsAssignableFrom<IGeneralDrivelution>(updater);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

DriverUpdaterFactory.Create() throws PlatformNotSupportedException on MacOS/unsupported platforms, so this test will fail when run there. Consider branching on GetCurrentPlatform() and asserting the exception for MacOS/Unknown (or skipping), so the test suite is portable across runners.

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +25
[Fact]
public void Create_WithoutParameters_ReturnsNonNullInstance()
{
// Act
var updater = GeneralDrivelution.Create();

// Assert
Assert.NotNull(updater);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

These Create(...) entry-point tests assume the platform is supported, but GeneralDrivelution.Create() will throw on MacOS/unsupported platforms (via DriverUpdaterFactory.Create). To avoid platform-dependent failures, gate the test (skip) or assert the expected exception when GetPlatformInfo().IsSupported is false.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +155
/// </summary>
[Fact]
public async Task QuickUpdateAsync_WithMinimalParameters_HandlesGracefully()
{
// Arrange
var testFilePath = Path.Combine(Path.GetTempPath(), $"test_driver_{Guid.NewGuid()}.txt");
File.WriteAllText(testFilePath, "Test driver content");

try
{
var driverInfo = new DriverInfo
{
Name = "Test Driver",
Version = "1.0.0",
FilePath = testFilePath,
TargetOS = "",
Architecture = ""
};

// Act
var result = await GeneralDrivelution.QuickUpdateAsync(driverInfo);

// Assert
Assert.NotNull(result);
// The result might fail due to validation or permissions, but should not crash
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

This test calls GeneralDrivelution.QuickUpdateAsync, which can execute real driver installation steps when run with admin/root privileges (Windows: ExecuteDriverInstallationAsync, Linux: ExecuteDriverInstallationAsync). To keep this as a safe unit test, avoid using an actual file path (force validation failure early), or explicitly skip when running elevated so the test can’t modify the host system.

Copilot uses AI. Check for mistakes.
Comment on lines +237 to +238
// Assert - Should return a boolean value without throwing
// No assertion needed - the test passes if no exception is thrown
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

ValidateAsync_WithMinimalDriverInfo_ReturnsBooleanResult doesn’t assert anything about the returned value (the result is unused). If the intention is “doesn’t throw”, rename the test accordingly; otherwise add an assertion that verifies the expected true/false outcome for the given input so the test actually detects regressions.

Suggested change
// Assert - Should return a boolean value without throwing
// No assertion needed - the test passes if no exception is thrown
// Assert - validation should succeed for an existing minimal driver file
Assert.True(result);

Copilot uses AI. Check for mistakes.
Comment on lines +381 to +382
Assert.True(RestartHelper.IsRestartRequired(RestartMode.None) == false);
Assert.True(RestartHelper.IsRestartRequired(RestartMode.Prompt) == true);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

This “callable” test is asserting boolean comparisons via Assert.True(x == false/true), which reduces readability and makes failures less clear. Prefer Assert.False(...) / Assert.True(...) directly (or remove the redundancy since IsRestartRequired is already covered by the focused tests above).

Suggested change
Assert.True(RestartHelper.IsRestartRequired(RestartMode.None) == false);
Assert.True(RestartHelper.IsRestartRequired(RestartMode.Prompt) == true);
Assert.False(RestartHelper.IsRestartRequired(RestartMode.None));
Assert.True(RestartHelper.IsRestartRequired(RestartMode.Prompt));

Copilot uses AI. Check for mistakes.
Comment on lines +168 to +203
/// <summary>
/// Tests that QuickUpdateAsync with custom strategy works.
/// </summary>
[Fact]
public async Task QuickUpdateAsync_WithCustomStrategy_HandlesGracefully()
{
// Arrange
var testFilePath = Path.Combine(Path.GetTempPath(), $"test_driver_{Guid.NewGuid()}.txt");
File.WriteAllText(testFilePath, "Test driver content");

try
{
var driverInfo = new DriverInfo
{
Name = "Test Driver",
Version = "1.0.0",
FilePath = testFilePath,
TargetOS = "",
Architecture = ""
};

var strategy = new UpdateStrategy
{
RequireBackup = false,
RetryCount = 1,
RetryIntervalSeconds = 1
};

// Act
var result = await GeneralDrivelution.QuickUpdateAsync(driverInfo, strategy);

// Assert
Assert.NotNull(result);
// Verify that result status is one of the valid enum values
Assert.True(Enum.IsDefined(typeof(UpdateStatus), result.Status));
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

Same concern as the other QuickUpdate test: if the runner has elevated privileges, this can progress past validation and attempt a real driver install. To keep tests non-invasive, force an early failure (e.g., non-existent path) or skip when elevated so CI/dev machines can’t be modified by running the unit suite.

Copilot uses AI. Check for mistakes.
Comment on lines +272 to +301
/// <summary>
/// Tests that QuickUpdateAsync with cancellation token works.
/// </summary>
[Fact]
public async Task QuickUpdateAsync_WithCancellationToken_CanBeCancelled()
{
// Arrange
var testFilePath = Path.Combine(Path.GetTempPath(), $"test_driver_{Guid.NewGuid()}.txt");
File.WriteAllText(testFilePath, "Test driver content");

try
{
var driverInfo = new DriverInfo
{
Name = "Test Driver",
Version = "1.0.0",
FilePath = testFilePath
};

var cts = new CancellationTokenSource();
cts.Cancel();

// Act & Assert
// Should either complete quickly or throw cancellation exception
var exception = await Record.ExceptionAsync(
() => GeneralDrivelution.QuickUpdateAsync(driverInfo, cts.Token));

// Either succeeded, failed gracefully, or was cancelled
Assert.True(exception == null || exception is OperationCanceledException);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

This cancellation test still invokes QuickUpdateAsync, which may have side effects if the update starts before cancellation is observed (especially if running elevated). Consider using an input that guarantees validation fails immediately, or explicitly skip when running elevated to avoid any chance of executing installation steps during tests.

Copilot uses AI. Check for mistakes.
JusterZhu added a commit that referenced this pull request Feb 9, 2026
* add GeneralUpdate.Drivelution

* Add comprehensive documentation for GeneralUpdate.Drivelution (#139)

* Initial plan

* Add comprehensive README documentation for GeneralUpdate.Drivelution

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Add comprehensive test suite for GeneralUpdate.Drivelution (#140)

* Initial plan

* Add comprehensive test cases for GeneralUpdate.Drivelution

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Address code review feedback: improve test quality and cleanup

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Rename DriverUpdate to Drivelution across codebase (#141)

* Initial plan

* Replace all instances of DriverUpdate with Drivelution

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Update error code prefixes from DU_ to DR_

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Add GetDriversFromDirectoryAsync for local driver discovery (#142)

* Initial plan

* Add GetDriversFromDirectoryAsync method to read driver information from local directory

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Add tests for GetDriversFromDirectoryAsync method

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Fix security issues: prevent command injection and improve certificate parsing

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

* Translate all Chinese annotations to English

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
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.

[FEATURE] Driver Upgrade Function

2 participants