tests/WindowsFeatures.Tests.ps1
|
$moduleRoot = Split-Path -Parent $PSScriptRoot Import-Module (Join-Path $moduleRoot 'Octa.psd1') -Force . (Join-Path $moduleRoot 'private\ActionHelpers.ps1') . (Join-Path $moduleRoot 'private\ElevationCheck.ps1') Get-ChildItem -Path (Join-Path $moduleRoot 'categories') -Filter '*.ps1' | ForEach-Object { . $_.FullName } # Get-WindowsOptionalFeature -Online requires elevation even to read - same real-world # constraint Appx's Get-AppxPackage -AllUsers already has, which Categories.Tests.ps1's generic # loop already works around the same way. $isElevated = Test-OctaElevation Describe 'Get-OctaWindowsFeaturesActions' { It 'never throws regardless of edition/build (Sandbox/WSL/Edge availability varies)' { if (-not $isElevated) { return } { Get-OctaWindowsFeaturesActions } | Should Not Throw } It 'reports Edge removal as Risky and non-reversible when Edge is present' { if (-not $isElevated) { return } $actions = Get-OctaWindowsFeaturesActions $edgeAction = $actions | Where-Object { $_.TargetIdentifier -eq 'MicrosoftEdge' } if ($edgeAction) { $edgeAction.RiskLevel | Should Be 'Risky' $edgeAction.Reversible | Should Be $false $edgeAction.IrreversibleReason | Should Not BeNullOrEmpty } } It 'omits Sandbox entirely on editions that do not support it (Home/Core)' { if (-not $isElevated) { return } $editionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID' -ErrorAction SilentlyContinue).EditionID if ($editionId -match 'Core|Home') { $actions = Get-OctaWindowsFeaturesActions ($actions | Where-Object { $_.TargetIdentifier -eq 'Containers-DisposableClientVM' }) | Should Be $null } } } |