@@ -9,33 +9,35 @@ BeforeDiscovery {
9
9
}
10
10
}
11
11
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' {
14
26
$out = dsc resource get - r Microsoft.Windows/ RebootPending | ConvertFrom-Json
15
27
$LASTEXITCODE | Should - Be 0
16
28
$out.actualState.rebootPending | Should -Not - BeNullOrEmpty
17
29
}
18
30
19
- It ' reboot_pending works in a config' - Skip:( ! $IsWindows ) {
31
+ It ' reboot_pending works in a config' {
20
32
$ConfigPath = Resolve-Path " $PSScriptRoot /reboot_pending.dsc.yaml"
21
33
$out = dsc config get -- file $ConfigPath | ConvertFrom-Json
22
34
$LASTEXITCODE | Should - Be 0
23
35
$out.results.result.actualState.rebootPending | Should -Not - BeNullOrEmpty
24
36
}
25
37
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 )
40
42
}
41
43
}
0 commit comments