config-central/tests/Packages.Tests.ps1

70 lines
3.1 KiB
PowerShell

BeforeAll {
Import-Module "$PSScriptRoot/../src/Packages.psm1" -Force
}
Describe 'Package planning' {
It 'plans missing, pinned, and install-only packages' {
$packages = @(
[pscustomobject]@{ id = 'Missing.App'; source = 'winget'; update = 'latest' },
[pscustomobject]@{ id = 'Pinned.App'; source = 'winget'; update = 'pinned'; version = '2.0' },
[pscustomobject]@{ id = 'Stable.App'; source = 'winget'; update = 'install-only' }
)
$inventory = [ordered]@{
'winget/pinned.app' = [pscustomobject]@{ version = '1.0' }
'winget/stable.app' = [pscustomobject]@{ version = '5.0' }
}
$plan = Get-PackagePlan -Packages $packages -Inventory $inventory
$plan.action | Should -Be @('Install', 'Install', 'None')
}
It 'leaves an installed version newer than a pin' {
$package = [pscustomobject]@{ id = 'Pinned.App'; source = 'winget'; update = 'pinned'; version = '2.0' }
$inventory = @{ 'winget/pinned.app' = [pscustomobject]@{ version = '3.0' } }
(Get-PackagePlan -Packages @($package) -Inventory $inventory)[0].action | Should -Be 'Warning'
}
It 'continues after an individual package failure' {
InModuleScope Packages {
Mock Invoke-PackageOperation {
if ($Operation.name -eq 'bad') { return [pscustomobject]@{ name = 'bad'; status = 'Failed' } }
[pscustomobject]@{ name = $Operation.name; status = 'Succeeded' }
}
$results = Invoke-PackagePlan -Plan @([pscustomobject]@{ name = 'bad' }, [pscustomobject]@{ name = 'good' })
$results.status | Should -Be @('Failed', 'Succeeded')
}
}
}
Describe 'WinGet signed process exit codes' {
It 'preserves the HRESULT bits and diagnostics for a negative exit code' {
InModuleScope Packages {
Mock Start-Process {
'WinGet diagnostic' | Set-Content -LiteralPath $RedirectStandardError
[pscustomobject]@{ ExitCode = -1978335189 }
}
$result = Invoke-WingetCapture -Arguments @('export')
$result.exitCode | Should -Be -1978335189
$result.unsignedExitCode | Should -Be 2316632107
$result.output | Should -Match 'WinGet diagnostic'
{ $result | ConvertTo-Json } | Should -Not -Throw
}
}
It 'recognizes a signed no-applicable-upgrade result' {
InModuleScope Packages {
Mock Start-Process { [pscustomobject]@{ ExitCode = -1978335189 } }
$operation = [pscustomobject]@{
action = 'Upgrade'; name = 'Test.App'
package = [pscustomobject]@{ id = 'Test.App'; source = 'winget' }
}
(Invoke-PackageOperation -Operation $operation).status | Should -Be 'Unchanged'
}
}
It 'preserves ordinary reboot exit codes' {
InModuleScope Packages {
Mock Start-Process { [pscustomobject]@{ ExitCode = 3010 } }
$result = Invoke-WingetCapture -Arguments @('install')
$result.unsignedExitCode | Should -Be 3010
}
}
}