File tree Expand file tree Collapse file tree 5 files changed +39
-9
lines changed Expand file tree Collapse file tree 5 files changed +39
-9
lines changed Original file line number Diff line number Diff line change 1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
4
+ BeforeDiscovery {
5
+ try {
6
+ $windowWidth = [Console ]::WindowWidth
7
+ } catch {
8
+ $consoleUnavailable = $true
9
+ }
10
+ }
11
+
4
12
Describe ' Discover extension tests' {
5
13
BeforeAll {
6
14
$oldPath = $env: PATH
@@ -110,12 +118,12 @@ Describe 'Discover extension tests' {
110
118
}
111
119
}
112
120
113
- It ' Table can be not truncated' {
121
+ It ' Table can be not truncated' - Skip:( $consoleUnavailable ) {
114
122
$output = dsc extension list -- output- format table- no- truncate
115
123
$LASTEXITCODE | Should - Be 0
116
124
$foundWideLine = $false
117
125
foreach ($line in $output ) {
118
- if ($line.Length -gt [ Console ]::WindowWidth ) {
126
+ if ($line.Length -gt $windowWidth ) {
119
127
$foundWideLine = $true
120
128
}
121
129
}
Original file line number Diff line number Diff line change 1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
4
+ BeforeDiscovery {
5
+ try {
6
+ $windowWidth = [Console ]::WindowWidth
7
+ } catch {
8
+ $consoleUnavailable = $true
9
+ }
10
+ }
11
+
4
12
Describe ' Tests for listing resources' {
5
13
It ' dsc resource list' {
6
14
$resources = dsc resource list | ConvertFrom-Json - Depth 10
@@ -89,12 +97,12 @@ Describe 'Tests for listing resources' {
89
97
$out | Should - BeLike " *ERROR*Adapter not found: foo`*"
90
98
}
91
99
92
- It ' Table is not truncated' {
100
+ It ' Table is not truncated' - Skip:( $consoleUnavailable ) {
93
101
$output = dsc resource list -- output- format table- no- truncate
94
102
$LASTEXITCODE | Should - Be 0
95
103
$foundWideLine = $false
96
104
foreach ($line in $output ) {
97
- if ($line.Length -gt [ Console ]::WindowWidth ) {
105
+ if ($line.Length -gt $windowWidth ) {
98
106
$foundWideLine = $true
99
107
break
100
108
}
Original file line number Diff line number Diff line change 1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
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 ) {
5
9
It ' Should find DSC appx resources' {
6
10
$out = dsc resource list | ConvertFrom-Json
7
11
$LASTEXITCODE | Should - Be 0
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ Describe 'Bicep extension tests' -Skip:(!$foundBicep) {
15
15
$out = dsc - l trace config get -f $bicepFile 2> $TestDrive / error.log | ConvertFrom-Json
16
16
$LASTEXITCODE | Should - Be 0 - Because (Get-Content - Path $TestDrive / error.log - Raw | Out-String )
17
17
$out.results [0 ].result.actualState.output | Should - BeExactly ' Hello, world!'
18
+ $bicepFile = $bicepFile.ToString ().Replace(' \' , ' \\' )
18
19
(Get-Content - Path $TestDrive / error.log - Raw) | Should -Match " Importing file '$bicepFile ' with extension 'Microsoft.DSC.Extension/Bicep'"
19
20
}
20
21
@@ -28,9 +29,10 @@ resource invalid 'Microsoft.DSC.Extension/Bicep:1.0' = {
28
29
properties: {
29
30
output: 'This is invalid'
30
31
"@
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
32
33
$LASTEXITCODE | Should - Be 4 - Because (Get-Content - Path $TestDrive / error.log - Raw | Out-String )
33
34
$content = (Get-Content - Path $TestDrive / error.log - Raw)
35
+ $bicepFile = $bicepFile.ToString ().Replace(' \' , ' \\' )
34
36
$content | Should -Match " Importing file '$bicepFile ' with extension 'Microsoft.DSC.Extension/Bicep'"
35
37
$content | Should -Match " BCP033"
36
38
}
Original file line number Diff line number Diff line change 1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
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
+
4
12
Describe ' reboot_pending resource tests' {
5
13
It ' should get reboot_pending' - Skip:(! $IsWindows ) {
6
14
$out = dsc resource get - r Microsoft.Windows/ RebootPending | ConvertFrom-Json
@@ -15,17 +23,17 @@ Describe 'reboot_pending resource tests' {
15
23
$out.results.result.actualState.rebootPending | Should -Not - BeNullOrEmpty
16
24
}
17
25
18
- It ' reboot_pending should have a reason' - Skip:(! $IsWindows ) {
26
+ It ' reboot_pending should have a reason' - Skip:(! $IsWindows -or ! $isElevated ) {
19
27
$keyPath = " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
20
28
$keyName = " RebootRequired"
21
29
try {
22
30
if (-not (Get-ItemProperty " $keyPath \$keyName " - ErrorAction SilentlyContinue)) {
23
31
New-ItemProperty - Path $keyPath - Name $keyName - Value 1 - PropertyType DWord - Force | Out-Null
24
32
}
25
33
26
- $out | dsc resource get - r Microsoft.Windows/ RebootPending | ConvertFrom-Json
34
+ $out = dsc resource get - r Microsoft.Windows/ RebootPending | ConvertFrom-Json
27
35
$LASTEXITCODE | Should - Be 0
28
- $out.actualState.reason.count | Should - BeGreaterThan 0
36
+ $out.actualState.reason.count | Should - BeGreaterThan 0 - Because ( $out | Out-String )
29
37
} finally {
30
38
Remove-ItemProperty - Path $keyPath - Name $keyName - ErrorAction Ignore
31
39
}
You can’t perform that action at this time.
0 commit comments