Skip to content

Commit

Permalink
test passing _Driver tests after only one device (#83)
Browse files Browse the repository at this point in the history
Up until now I've always required that all matched / found HardwareIDs
in a _Driver test pass their tests for the overall _Driver test to pass,
but #83 shows this might not be correct. This adds a test variable to
easily compare results with the old vs this approach to test regressions
  • Loading branch information
jantari committed Mar 27, 2023
1 parent 0a40391 commit fbd2984
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions private/Test-MachineSatisfiesDependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@

if ($DevicesToTest.Count -ge 1) {
$TestResults = [System.Collections.Generic.List[bool]]::new()
$PerDeviceTestResults = [System.Collections.Generic.List[bool]]::new()
foreach ($Device in $DevicesToTest) {
$PerDeviceTestResults.Clear()
Write-Debug "$('- ' * $DebugIndent)Testing $($Device.DeviceId)"
# First, check if there is a driver installed for the device at all before proceeding (issue#24)
if ($Device.Problem -eq 'CM_PROB_FAILED_INSTALL') {
Expand Down Expand Up @@ -181,10 +183,10 @@
Write-Debug "$('- ' * $DebugIndent)[Got: $DriverDate, Expected: $LenovoDate]"
if ($DriverDate -ge $LenovoDate) {
Write-Debug "$('- ' * $DebugIndent)Passed DriverDate test"
$TestResults.Add($true)
$PerDeviceTestResults.Add($true)
} else {
Write-Debug "$('- ' * $DebugIndent)Failed DriverDate test"
$TestResults.Add($false)
$PerDeviceTestResults.Add($false)
}
} else {
Write-Verbose "Device '$($Device.InstanceId)' does not report its driver date"
Expand All @@ -201,18 +203,26 @@
Write-Debug "$('- ' * $DebugIndent)[Got: $DriverVersion, Expected: $($Dependency.Version)]"
if ((Test-VersionPattern -LenovoString $Dependency.Version -SystemString $DriverVersion) -eq 0) {
Write-Debug "$('- ' * $DebugIndent)Passed DriverVersion test"
$TestResults.Add($true)
$PerDeviceTestResults.Add($true)
} else {
Write-Debug "$('- ' * $DebugIndent)Failed DriverVersion test"
$TestResults.Add($false)
$PerDeviceTestResults.Add($false)
}
} else {
Write-Verbose "Device '$($Device.InstanceId)' does not report its driver version"
}
}

# If all HardwareID-tests were successful for even just one HardwareID, return SUCCESS
if ($env:LSUCLIENT_PASS_DRIVER_ONE_HARDWAREID -and -not ($PerDeviceTestResults -contains $false)) {
return 0 #SUCCESS
}

$TestResults.AddRange($PerDeviceTestResults)
## end of foreach device loop
}

# If all HardwareID-tests were successful, return SUCCESS
# If all HardwareID-tests were successful for ALL HardwareIDs, return SUCCESS
if (-not ($TestResults -contains $false)) {
return 0 #SUCCESS
}
Expand Down

1 comment on commit fbd2984

@github-actions
Copy link

Choose a reason for hiding this comment

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

PSScriptAnalyzer results as of this commit:

  • 2 Information
  • 8 Warning
See details
Location : ./public/Set-LSUClientConfiguration.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-LSUClientConfiguration' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./public/Install-LSUpdate.ps1 [135, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Install-LSUpdate.ps1 [172, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./private/Resolve-XMLDependencies.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Resolve-XMLDependencies' uses a plural noun. A singular noun shou
           ld be used instead.

Location : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used. 

Location : ./private/Invoke-PackageCommand.ps1 [303, 29]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Split-ExecutableAndArguments.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Split-ExecutableAndArguments' uses a plural noun. A singular noun
            should be used instead.

Location : ./private/Debug-LongRunningProcess.ps1 [44, 13]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [139, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' has been declared but not used. 

Location : ./private/Set-BIOSUpdateRegistryFlag.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Please sign in to comment.