mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-08-23 08:02:07 +00:00
fix: improve error handling for registry file imports and telemetry scheduled tasks
This commit is contained in:
@@ -67,6 +67,18 @@ Describe 'Test-ConfigConsistency' {
|
||||
Test-ConfigConsistency -Config $config | Should -Match 'Apps entries must be strings'
|
||||
}
|
||||
|
||||
It 'reports an error for malformed tweak entries' {
|
||||
$config = [PSCustomObject]@{ Version = '1.0'; Tweaks = @(@{ Value = $true }) }
|
||||
|
||||
Test-ConfigConsistency -Config $config | Should -Match 'Tweaks entries must contain Name and Value properties'
|
||||
}
|
||||
|
||||
It 'reports an error for deployment entries missing a required property' {
|
||||
$config = [PSCustomObject]@{ Version = '1.0'; Deployment = @(@{ Name = 'CreateRestorePoint' }) }
|
||||
|
||||
Test-ConfigConsistency -Config $config | Should -Match 'Deployment entries must contain Name and Value properties'
|
||||
}
|
||||
|
||||
It 'reports an error for nonnumeric deployment indexes' {
|
||||
$config = [PSCustomObject]@{
|
||||
Version = '1.0'
|
||||
|
||||
@@ -26,6 +26,13 @@ Describe 'Import-RegistryFile' {
|
||||
Should -Invoke Invoke-NonBlocking -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It 'returns false when registry file resolution throws' {
|
||||
Mock Get-RegistryFilePathForFeature { throw 'path resolution failed' }
|
||||
|
||||
Import-RegistryFile -message 'Apply' -path 'feature.reg' | Should -BeFalse
|
||||
Should -Invoke Invoke-NonBlocking -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It 'uses the PowerShell writer only in WhatIf mode' {
|
||||
$script:Params = @{ WhatIf = $true }
|
||||
Import-RegistryFile -message 'Apply' -path 'feature.reg' | Should -BeTrue
|
||||
|
||||
@@ -95,6 +95,35 @@ Describe 'Disable-TelemetryScheduledTasks' {
|
||||
$result.Error | Should -Match 'access denied'
|
||||
}
|
||||
|
||||
It 'returns an error when scheduled-task lookup fails' {
|
||||
Mock Invoke-NonBlocking {
|
||||
param($ScriptBlock, $ArgumentList)
|
||||
$script:taskBlock = $ScriptBlock
|
||||
$script:taskArguments = $ArgumentList
|
||||
}
|
||||
Mock Import-Module {}
|
||||
Mock Get-ScheduledTask { throw 'scheduler unavailable' }
|
||||
|
||||
Disable-TelemetryScheduledTasks
|
||||
$result = & $script:taskBlock @script:taskArguments
|
||||
|
||||
$result.Status | Should -Be 'Error'
|
||||
$result.Error | Should -Match 'scheduler unavailable'
|
||||
}
|
||||
|
||||
It 'treats an absent scheduled task as not found' {
|
||||
Mock Invoke-NonBlocking {
|
||||
param($ScriptBlock, $ArgumentList)
|
||||
$script:taskBlock = $ScriptBlock
|
||||
$script:taskArguments = $ArgumentList
|
||||
}
|
||||
Mock Import-Module {}
|
||||
Mock Get-ScheduledTask { $null }
|
||||
|
||||
Disable-TelemetryScheduledTasks
|
||||
(& $script:taskBlock @script:taskArguments).Status | Should -Be 'NotFound'
|
||||
}
|
||||
|
||||
It 'reports <Status> task results' -ForEach @(
|
||||
@{ Status = 'Disabled'; Expected = 'Disabled Scheduled Task' }
|
||||
@{ Status = 'AlreadyDisabled'; Expected = 'already disabled' }
|
||||
@@ -175,6 +204,22 @@ Describe 'Enable-TelemetryScheduledTasks' {
|
||||
Should -Invoke Enable-ScheduledTask -Times 1 -Exactly -ParameterFilter { $TaskPath -eq '\Microsoft\Windows\Test\' -and $TaskName -eq 'Second' }
|
||||
}
|
||||
|
||||
It 'returns an error when scheduled-task lookup fails' {
|
||||
Mock Invoke-NonBlocking {
|
||||
param($ScriptBlock, $ArgumentList)
|
||||
$script:taskBlock = $ScriptBlock
|
||||
$script:taskArguments = $ArgumentList
|
||||
}
|
||||
Mock Import-Module {}
|
||||
Mock Get-ScheduledTask { throw 'scheduler unavailable' }
|
||||
|
||||
Enable-TelemetryScheduledTasks
|
||||
$result = & $script:taskBlock @script:taskArguments
|
||||
|
||||
$result.Status | Should -Be 'Error'
|
||||
$result.Error | Should -Match 'scheduler unavailable'
|
||||
}
|
||||
|
||||
It 'reports <Status> task results' -ForEach @(
|
||||
@{ Status = 'Enabled'; Expected = 'Enabled Scheduled Task' }
|
||||
@{ Status = 'AlreadyEnabled'; Expected = 'already enabled' }
|
||||
|
||||
Reference in New Issue
Block a user