Skip to content

Commit fb583ab

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
fix reboot pending test
1 parent 7862a86 commit fb583ab

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

reboot_pending/tests/reboot_pending.tests.ps1

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,35 @@ BeforeDiscovery {
99
}
1010
}
1111

12-
Describe 'reboot_pending resource tests' {
13-
It 'should get reboot_pending' -Skip:(!$IsWindows) {
12+
Describe 'reboot_pending resource tests' -Skip:(!$IsWindows -or !$isElevated) {
13+
BeforeAll {
14+
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
15+
$keyName = "RebootRequired"
16+
if (-not (Get-ItemProperty "$keyPath\$keyName" -ErrorAction SilentlyContinue)) {
17+
New-ItemProperty -Path $keyPath -Name $keyName -Value 1 -PropertyType DWord -Force | Out-Null
18+
}
19+
}
20+
21+
AfterAll {
22+
Remove-ItemProperty -Path $keyPath -Name $keyName -ErrorAction Ignore
23+
}
24+
25+
It 'should get reboot_pending' {
1426
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
1527
$LASTEXITCODE | Should -Be 0
1628
$out.actualState.rebootPending | Should -Not -BeNullOrEmpty
1729
}
1830

19-
It 'reboot_pending works in a config' -Skip:(!$IsWindows) {
31+
It 'reboot_pending works in a config' {
2032
$ConfigPath = Resolve-Path "$PSScriptRoot/reboot_pending.dsc.yaml"
2133
$out = dsc config get --file $ConfigPath | ConvertFrom-Json
2234
$LASTEXITCODE | Should -Be 0
2335
$out.results.result.actualState.rebootPending | Should -Not -BeNullOrEmpty
2436
}
2537

26-
It 'reboot_pending should have a reason' -Skip:(!$IsWindows -or !$isElevated) {
27-
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
28-
$keyName = "RebootRequired"
29-
try {
30-
if (-not (Get-ItemProperty "$keyPath\$keyName" -ErrorAction SilentlyContinue)) {
31-
New-ItemProperty -Path $keyPath -Name $keyName -Value 1 -PropertyType DWord -Force | Out-Null
32-
}
33-
34-
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
35-
$LASTEXITCODE | Should -Be 0
36-
$out.actualState.reason.count | Should -BeGreaterThan 0 -Because ($out | Out-String)
37-
} finally {
38-
Remove-ItemProperty -Path $keyPath -Name $keyName -ErrorAction Ignore
39-
}
38+
It 'reboot_pending should have a reason' {
39+
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
40+
$LASTEXITCODE | Should -Be 0
41+
$out.actualState.reason.count | Should -BeGreaterThan 0 -Because ($out | Out-String)
4042
}
4143
}

0 commit comments

Comments
 (0)