config-central/tests/Core.Tests.ps1

36 lines
2.0 KiB
PowerShell

BeforeAll {
foreach ($module in @('State', 'Manifest', 'Repository', 'Packages', 'Configs', 'Elevation', 'Scheduling', 'Core')) {
Import-Module "$PSScriptRoot/../src/$module.psm1" -Force
}
}
Describe 'Core workflow policy' {
It 'does not inventory or change packages in config-only mode' {
InModuleScope Core -Parameters @{ Working = $TestDrive } {
Mock Read-JsonState { @{ configs = @{} } }
Mock Resolve-MachineManifest { [pscustomobject]@{ packages = @([pscustomobject]@{ id = 'Never.Run' }); configs = @() } }
Mock Get-WingetInventory { throw 'WinGet must not run' }
Mock Get-ConfigPlan { @() }
$paths = [pscustomobject]@{ Settings = "$Working/settings.json"; State = "$Working/state.json" }
$plan = Get-OperationPlan -Machine test -RepositoryRoot $Working -Paths $paths -ConfigsOnly
$plan.packages.Count | Should -Be 0
Should -Invoke Get-WingetInventory -Times 0
}
}
It 'returns the stable reboot-required exit code after successful work' {
InModuleScope Core -Parameters @{ Working = $TestDrive } {
Mock Invoke-PackageOperation { [pscustomobject]@{ name = 'Reboot.App'; status = 'Succeeded'; rebootRequired = $true; message = 'Installed; reboot required' } }
$paths = Get-ConfigCentralPaths -DataRoot (Join-Path $Working 'reboot-data')
$operation = [pscustomobject]@{
kind = 'package'; name = 'Reboot.App'; action = 'Install'; reason = 'Missing'
package = [pscustomobject]@{ id = 'Reboot.App'; source = 'winget'; update = 'latest' }
}
$plan = [pscustomobject]@{ packages = @($operation); configs = @(); state = @{ schemaVersion = 1; configs = @{} } }
$result = Invoke-ApplyPlan -Plan $plan -Machine test -RepositoryRoot $Working -Paths $paths -Revision abc
$result.succeeded | Should -BeTrue
$result.exitCode | Should -Be 6
}
}
}