@@ -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