8000 [Feature] · PowerShell/PowerShell@d78e9ba · GitHub
[go: up one dir, main page]

Skip to content

Commit d78e9ba

Browse files
committed
[Feature]
In CI, notepad.exe isn't starting (or starting in time) when using start-process with .txt based on file association. Since the test is validating opening files by association, fix is to create our own association that is predictable.
1 parent 700a1c4 commit d78e9ba

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,24 @@ try {
13831383
"2"< 8000 /span> = "HypervisorEnforcedCodeIntegrity"
13841384
}
13851385
$observed.DeviceGuardSmartStatus | Should Be (Get-StringValuesFromValueMap -valuemap $smartStatusValues -values $deviceGuard.SmartStatus)
1386-
[string]::Join(",", $observed.DeviceGuardRequiredSecurityProperties) | Should Be (Get-StringValuesFromValueMap -valuemap $requiredSecurityPropertiesValues -values $deviceGuard.RequiredSecurityProperties)
1386+
if ($deviceGuard.RequiredSecurityProperties -eq $null)
1387+
{
1388+
$observed.DeviceGuardRequiredSecurityProperties | Should BeNullOrEmpty
1389+
}
1390+
else
1391+
{
1392+
[string]::Join(",", $observed.DeviceGuardRequiredSecurityProperties) | Should Be (Get-StringValuesFromValueMap -valuemap $requiredSecurityPropertiesValues -values $deviceGuard.RequiredSecurityProperties)
1393+
}
13871394
$observed.DeviceGuardAvailableSecurityProperties | Should Be $deviceGuard.AvailableSecurityProperties
13881395
$observed.DeviceGuardSecurityServicesConfigured | Should Be $deviceGuard.SecurityServicesConfigured
1389-
[string]::Join(",", $observed.DeviceGuardSecurityServicesRunning) | Should Be (Get-StringValuesFromValueMap -valuemap $securityServicesRunningValues -values $deviceGuard.SecurityServicesRunning)
1396+
if ($deviceGuard.SecurityServicesRunning -eq $null)
1397+
{
1398+
$observed.DeviceGuardSecurityServicesRunning | Should BeNullOrEmpty
1399+
}
1400+
else
1401+
{
1402+
[string]::Join(",", $observed.DeviceGuardSecurityServicesRunning) | Should Be (Get-StringValuesFromValueMap -valuemap $securityServicesRunningValues -values $deviceGuard.SecurityServicesRunning)
1403+
}
13901404
$observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.CodeIntegrityPolicyEnforcementStatus
13911405
$observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.UserModeCodeIntegrityPolicyEnforcementStatus
13921406
}

test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Describe "Start-Process" -Tags @("CI","SLOW") {
1+
Describe "Start-Process" -Tags @("Feature") {
22

33
BeforeAll {
44
$isNanoServer = [System.Management.Automation.Platform]::IsNanoServer
@@ -10,7 +10,7 @@ Describe "Start-Process" -Tags @("CI","SLOW") {
1010
$tempFile = Join-Path -Path $TestDrive -ChildPath PSTest
1111
$assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt
1212
if ($IsWindows) {
13-
$pingParam = "-n 2 localhost"
13+
$pingParam = "-n 2 localhost"
1414
}
1515
elseif ($IsLinux -Or $IsOSX) {
1616
$pingParam = "-c 2 localhost"
@@ -104,15 +104,31 @@ Describe "Start-Process" -Tags @("CI","SLOW") {
104104
$process.Name | Should Be "notepad"
105105
$process | Stop-Process
106106
}
107+
}
107108

108-
It "Should open the application that associates with extension '.txt'" -Skip:(!$isFullWin) {
109-
$txtFile = Join-Path $TestDrive "TxtTest.txt"
110-
New-Item $txtFile -ItemType File -Force
111-
$process = Start-Process $txtFile -PassThru -WindowStyle Normal
112-
$process.Name | Should Not BeNullOrEmpty
113-
$process.Id | Should BeGreaterThan 1
114-
$process | Stop-Process
109+
Describe "Start-Process tests requiring admin" -Tags "Feature","RequireAdminOnWindows" {
110+
111+
BeforeEach {
112+
cmd /c assoc .foo=foofile
113+
cmd /c ftype foofile=cmd /c echo %1^> $testdrive\foo.txt
114+
Remove-Item $testdrive\foo.txt -Force -ErrorAction SilentlyContinue
115115
}
116116

117-
Remove-Item -Path $tempFile -Force
117+
AfterEach {
118+
cmd /c assoc .foo=
119+
cmd /c ftype foofile=
120+
}
121+
122+
It "Should open the application that is associated a file" -Skip:(!$isFullWin) {
123+
$fooFile = Join-Path $TestDrive "FooTest.foo"
124+
New-Item $fooFile -ItemType File -Force
125+
Start-Process $fooFile
126+
$startTime = Get-Date
127+
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and (!(Test-Path $testdrive\foo.txt)))
128+
{
129+
Start-Sleep -Milliseconds 100
130+
}
131+
"$testdrive\foo.txt" | Should Exist
132+
Get-Content $testdrive\foo.txt | Should BeExactly $fooFile
133+
}
118134
}

0 commit comments

Comments
 (0)
0