Skip to content

Commit 7862a86

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
fix tests
1 parent 2578344 commit 7862a86

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
try {
6+
$windowWidth = [Console]::WindowWidth
7+
} catch {
8+
$consoleUnavailable = $true
9+
}
10+
}
11+
412
Describe 'Discover extension tests' {
513
BeforeAll {
614
$oldPath = $env:PATH
@@ -110,12 +118,12 @@ Describe 'Discover extension tests' {
110118
}
111119
}
112120

113-
It 'Table can be not truncated' {
121+
It 'Table can be not truncated' -Skip:($consoleUnavailable) {
114122
$output = dsc extension list --output-format table-no-truncate
115123
$LASTEXITCODE | Should -Be 0
116124
$foundWideLine = $false
117125
foreach ($line in $output) {
118-
if ($line.Length -gt [Console]::WindowWidth) {
126+
if ($line.Length -gt $windowWidth) {
119127
$foundWideLine = $true
120128
}
121129
}

dsc/tests/dsc_resource_list.tests.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
try {
6+
$windowWidth = [Console]::WindowWidth
7+
} catch {
8+
$consoleUnavailable = $true
9+
}
10+
}
11+
412
Describe 'Tests for listing resources' {
513
It 'dsc resource list' {
614
$resources = dsc resource list | ConvertFrom-Json -Depth 10
@@ -89,12 +97,12 @@ Describe 'Tests for listing resources' {
8997
$out | Should -BeLike "*ERROR*Adapter not found: foo`*"
9098
}
9199

92-
It 'Table is not truncated' {
100+
It 'Table is not truncated' -Skip:($consoleUnavailable) {
93101
$output = dsc resource list --output-format table-no-truncate
94102
$LASTEXITCODE | Should -Be 0
95103
$foundWideLine = $false
96104
foreach ($line in $output) {
97-
if ($line.Length -gt [Console]::WindowWidth) {
105+
if ($line.Length -gt $windowWidth) {
98106
$foundWideLine = $true
99107
break
100108
}

extensions/appx/appx.tests.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
Describe 'Tests for Appx resource discovery' -Skip:(!$IsWindows){
4+
BeforeDiscovery {
5+
$runningInCI = $null -ne $env:GITHUB_RUN_ID
6+
}
7+
8+
Describe 'Tests for Appx resource discovery' -Skip:(!$IsWindows -or $runningInCI) {
59
It 'Should find DSC appx resources' {
610
$out = dsc resource list | ConvertFrom-Json
711
$LASTEXITCODE | Should -Be 0

extensions/bicep/bicep.tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Describe 'Bicep extension tests' -Skip:(!$foundBicep) {
1515
$out = dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
1616
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
1717
$out.results[0].result.actualState.output | Should -BeExactly 'Hello, world!'
18+
$bicepFile = $bicepFile.ToString().Replace('\', '\\')
1819
(Get-Content -Path $TestDrive/error.log -Raw) | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
1920
}
2021

@@ -28,9 +29,10 @@ resource invalid 'Microsoft.DSC.Extension/Bicep:1.0' = {
2829
properties: {
2930
output: 'This is invalid'
3031
"@
31-
$out = dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
32+
dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
3233
$LASTEXITCODE | Should -Be 4 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
3334
$content = (Get-Content -Path $TestDrive/error.log -Raw)
35+
$bicepFile = $bicepFile.ToString().Replace('\', '\\')
3436
$content | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
3537
$content | Should -Match "BCP033"
3638
}

reboot_pending/tests/reboot_pending.tests.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
if ($IsWindows) {
6+
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
7+
$principal = [System.Security.Principal.WindowsPrincipal]::new($identity)
8+
$isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
9+
}
10+
}
11+
412
Describe 'reboot_pending resource tests' {
513
It 'should get reboot_pending' -Skip:(!$IsWindows) {
614
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
@@ -15,17 +23,17 @@ Describe 'reboot_pending resource tests' {
1523
$out.results.result.actualState.rebootPending | Should -Not -BeNullOrEmpty
1624
}
1725

18-
It 'reboot_pending should have a reason' -Skip:(!$IsWindows) {
26+
It 'reboot_pending should have a reason' -Skip:(!$IsWindows -or !$isElevated) {
1927
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
2028
$keyName = "RebootRequired"
2129
try {
2230
if (-not (Get-ItemProperty "$keyPath\$keyName" -ErrorAction SilentlyContinue)) {
2331
New-ItemProperty -Path $keyPath -Name $keyName -Value 1 -PropertyType DWord -Force | Out-Null
2432
}
2533

26-
$out | dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
34+
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
2735
$LASTEXITCODE | Should -Be 0
28-
$out.actualState.reason.count | Should -BeGreaterThan 0
36+
$out.actualState.reason.count | Should -BeGreaterThan 0 -Because ($out | Out-String)
2937
} finally {
3038
Remove-ItemProperty -Path $keyPath -Name $keyName -ErrorAction Ignore
3139
}

0 commit comments

Comments
 (0)