Skip to content

Commit 40532d9

Browse files
authored
Add VSTS CI for Windows (PowerShell#7536)
- Add VSTS CI for Windows - Disable `Access-denied test for Get-Item C:\windows\appcompat\Programs\Install -ErrorAction Stop`, because the path does not always exist - PowerShell#7553 - Disable `Should give .sys file if the fullpath is specified with hidden and force parameter`, because pagefile.sys doesn't always exist and other files don't meet test's requirement. - PowerShell#7554 - Disable some `Test-Connection` tests for same reasons they failed on VSTS Linux - PowerShell#7555 - Disable `Test-FileCatalog should pass when catalog is in the same folder as files being tested`, because the CmdLet does not work in that scenario - Also, give details needed to investigate when the test fails - PowerShell#7556 - Update `appveyor.psm1` to work with VSTS - Update `HelpersRemoting.psm1` `New-RemoteSession` to work for CimSession (discovered an issue during the investigation) - Update `Test wildcard with drive relative directory path` to work when there are multiple drives - Disable on non-windows machines since the test is assuming drive letters - Update `New-CimSession` Tests to requireAdmin - Also, make sure session name is a string - Add functions to save and restore psoptions - update `.gitatttributes` so files clone like they do on appveyor
1 parent 9fa97ad commit 40532d9

File tree

13 files changed

+245
-36
lines changed

13 files changed

+245
-36
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ CHANGELOG.md merge=union
22
* text=auto
33
*.png binary
44
*.rtf binary
5+
testablescript.ps1 text eol=lf
6+
TestFileCatalog.txt text eol=lf

.vsts-ci/windows.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
2+
queue:
3+
name: Hosted VS2017
4+
parallel: 2 # Limit to two agents at a time
5+
matrix:
6+
UnelevatedPesterTests:
7+
Purpose: UnelevatedPesterTests
8+
ElevatedPesterTests_xUnit_Packaging:
9+
Purpose: ElevatedPesterTests_xUnit_Packaging
10+
11+
variables:
12+
GIT_CONFIG_PARAMETERS: "'core.autocrlf=false'"
13+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
14+
POWERSHELL_TELEMETRY_OPTOUT: 1
15+
# Avoid expensive initialization of dotnet cli, see: http://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds
16+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
17+
18+
resources:
19+
- repo: self
20+
clean: true
21+
22+
steps:
23+
- powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))"
24+
displayName: Set Build Name for Non-PR
25+
condition: ne(variables['Build.Reason'], 'PullRequest')
26+
27+
- powershell: |
28+
git submodule update --init
29+
displayName: SubModule Init
30+
condition: succeededOrFailed()
31+
32+
- powershell: |
33+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
34+
Import-Module .\tools\Appveyor.psm1
35+
Invoke-AppveyorInstall
36+
displayName: Bootstrap
37+
condition: succeededOrFailed()
38+
39+
- powershell: |
40+
Import-Module .\tools\Appveyor.psm1
41+
Invoke-AppveyorBuild
42+
Save-PSOptions
43+
displayName: Build
44+
condition: succeeded()
45+
46+
- powershell: |
47+
Import-Module .\tools\Appveyor.psm1
48+
Restore-PSOptions
49+
Invoke-AppveyorTest -Purpose '$(Purpose)'
50+
displayName: Test
51+
condition: succeeded()
52+
53+
- powershell: |
54+
Import-Module .\tools\Appveyor.psm1
55+
Restore-PSOptions
56+
Invoke-AppveyorAfterTest
57+
displayName: AfterTest
58+
condition: succeededOrFailed()
59+
60+
- powershell: |
61+
Import-Module .\tools\Appveyor.psm1
62+
Restore-PSOptions
63+
Invoke-AppveyorFinish
64+
displayName: Finish
65+
condition: eq(variables['Purpose'], 'ElevatedPesterTests_xUnit_Packaging')

build.psm1

+106-10
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ function Get-EnvironmentInformation
116116
if ($Environment.IsWindows)
117117
{
118118
$environment += @{'IsAdmin' = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)}
119-
# Can't use $env:HOME - not available on older systems (e.g. in AppVeyor)
120-
$environment += @{'nugetPackagesRoot' = "${env:HOMEDRIVE}${env:HOMEPATH}\.nuget\packages"}
119+
$environment += @{'nugetPackagesRoot' = "${env:USERPROFILE}\.nuget\packages"}
121120
}
122121
else
123122
{
@@ -876,14 +875,15 @@ function New-PSOptions {
876875
$RootInfo['IsValid'] = $true
877876
}
878877

879-
return @{ RootInfo = [PSCustomObject]$RootInfo
880-
Top = $Top
881-
Configuration = $Configuration
882-
Framework = $Framework
883-
Runtime = $Runtime
884-
Output = $Output
885-
CrossGen = $CrossGen.IsPresent
886-
PSModuleRestore = $PSModuleRestore.IsPresent }
878+
return New-PSOptionsObject `
879+
-RootInfo ([PSCustomObject]$RootInfo) `
880+
-Top $Top `
881+
-Runtime $Runtime `
882+
-Crossgen $Crossgen.IsPresent `
883+
-Configuration $Configuration `
884+
-PSModuleRestore $PSModuleRestore.IsPresent `
885+
-Framework $Framework `
886+
-Output $Output
887887
}
888888

889889
# Get the Options of the last build
@@ -2996,6 +2996,102 @@ function Restore-PSOptions {
29962996
Set-PSOptions -Options $options
29972997
}
29982998

2999+
# Save PSOptions to be restored by Restore-PSOptions
3000+
function Save-PSOptions {
3001+
param(
3002+
[ValidateScript({$parent = Split-Path $_;if($parent){Test-Path $parent}else{return $true}})]
3003+
[ValidateNotNullOrEmpty()]
3004+
[string]
3005+
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),
3006+
3007+
[ValidateNotNullOrEmpty()]
3008+
[object]
3009+
$Options = (Get-PSOptions -DefaultToNew)
3010+
)
3011+
3012+
$Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath $PSOptionsPath
3013+
}
3014+
3015+
# Restore PSOptions
3016+
# Optionally remove the PSOptions file
3017+
function Restore-PSOptions {
3018+
param(
3019+
[ValidateScript({Test-Path $_})]
3020+
[string]
3021+
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),
3022+
[switch]
3023+
$Remove
3024+
)
3025+
3026+
$options = Get-Content -Path $PSOptionsPath | ConvertFrom-Json
3027+
3028+
if($Remove)
3029+
{
3030+
# Remove PSOptions.
3031+
# The file is only used to set the PSOptions.
3032+
Remove-Item -Path $psOptionsPath -Force
3033+
}
3034+
3035+
$newOptions = New-PSOptionsObject `
3036+
-RootInfo $options.RootInfo `
3037+
-Top $options.Top `
3038+
-Runtime $options.Runtime `
3039+
-Crossgen $options.Crossgen `
3040+
-Configuration $options.Configuration `
3041+
-PSModuleRestore $options.PSModuleRestore `
3042+
-Framework $options.Framework `
3043+
-Output $options.Output
3044+
3045+
Set-PSOptions -Options $newOptions
3046+
}
3047+
3048+
function New-PSOptionsObject
3049+
{
3050+
param(
3051+
[PSCustomObject]
3052+
$RootInfo,
3053+
3054+
[Parameter(Mandatory)]
3055+
[String]
3056+
$Top,
3057+
3058+
[Parameter(Mandatory)]
3059+
[String]
3060+
$Runtime,
3061+
3062+
[Parameter(Mandatory)]
3063+
[Bool]
3064+
$CrossGen,
3065+
3066+
[Parameter(Mandatory)]
3067+
[String]
3068+
$Configuration,
3069+
3070+
[Parameter(Mandatory)]
3071+
[Bool]
3072+
$PSModuleRestore,
3073+
3074+
[Parameter(Mandatory)]
3075+
[String]
3076+
$Framework,
3077+
3078+
[Parameter(Mandatory)]
3079+
[String]
3080+
$Output
3081+
)
3082+
3083+
return @{
3084+
RootInfo = $RootInfo
3085+
Top = $Top
3086+
Configuration = $Configuration
3087+
Framework = $Framework
3088+
Runtime = $Runtime
3089+
Output = $Output
3090+
CrossGen = $CrossGen
3091+
PSModuleRestore = $PSModuleRestore
3092+
}
3093+
}
3094+
29993095
$script:RESX_TEMPLATE = @'
30003096
<?xml version="1.0" encoding="utf-8"?>
30013097
<root>

test/powershell/Modules/CimCmdlets/CimSession.Tests.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ try {
55
$PSDefaultParameterValues['it:pending'] = $true
66
}
77

8-
Describe "New-CimSession" -Tag @("CI") {
8+
Describe "New-CimSession" -Tag @("CI","RequireAdminOnWindows") {
99
BeforeAll {
1010
$sessions = @()
1111
}
@@ -16,15 +16,15 @@ try {
1616
}
1717

1818
It "A cim session can be created" {
19-
$sessionName = [guid]::NewGuid()
19+
$sessionName = [guid]::NewGuid().Guid
2020
$session = New-CimSession -ComputerName . -Name $sessionName
2121
$sessions += $session
2222
$session.Name | Should -BeExactly $sessionName
2323
$session.InstanceId | Should -BeOfType "System.Guid"
2424
}
2525

2626
It "A Cim session can be retrieved" {
27-
$sessionName = [guid]::NewGuid()
27+
$sessionName = [guid]::NewGuid().Guid
2828
$session = New-CimSession -ComputerName . -Name $sessionName
2929
$sessions += $session
3030
(Get-CimSession -Name $sessionName).InstanceId | Should -Be $session.InstanceId
@@ -33,7 +33,7 @@ try {
3333
}
3434

3535
It "A cim session can be removed" {
36-
$sessionName = [guid]::NewGuid()
36+
$sessionName = [guid]::NewGuid().Guid
3737
$session = New-CimSession -ComputerName . -Name $sessionName
3838
$sessions += $session
3939
$session.Name | Should -BeExactly $sessionName

test/powershell/Modules/Microsoft.PowerShell.Core/Pester.Commands.Cmdlets.GetCommand.Tests.ps1

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
1616
$commandInfo = Get-Command Get-Date -ShowCommandInfo
1717
}
1818

19-
It "Test wildcard with drive relative directory path" {
19+
# this test doesn't test anything on non-windows platforms
20+
It "Test wildcard with drive relative directory path" -Skip:(!$IsWindows) {
2021
$pathName = Join-Path $TestDrive "WildCardCommandA*"
2122
$driveOffset = $pathName.IndexOf(":")
22-
$pathName = $pathName.Substring($driveOffset + 1)
23-
$result = Get-Command -Name $pathName
24-
$result | Should -Not -BeNullOrEmpty
25-
$result.Name | Should -Be WildCardCommandA.exe
23+
$driveName = $pathName.Substring(0,$driveOffset + 1)
24+
Push-Location -Path $driveName
25+
try {
26+
$pathName = $pathName.Substring($driveOffset + 1)
27+
$result = Get-Command -Name $pathName
28+
$result | Should -Not -BeNullOrEmpty
29+
$result.Name | Should -Be WildCardCommandA.exe
30+
}
31+
catch {
32+
Pop-Location
33+
}
2634
}
2735

2836
It "Test wildcard with relative directory path" {

test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
252252

253253
It "Access-denied test for <cmdline>" -Skip:(-not $IsWindows) -TestCases @(
254254
# NOTE: ensure the fileNameBase parameter is unique for each test case; it is used to generate a unique error and done file name.
255-
@{cmdline = "Get-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"}
255+
# The following test does not consistently work on windows
256+
# @{cmdline = "Get-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"}
256257
@{cmdline = "Get-ChildItem $protectedPath -ErrorAction Stop"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"}
257258
@{cmdline = "New-Item -Type File -Path $newItemPath -ErrorAction Stop"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"}
258259
@{cmdline = "Rename-Item -Path $protectedPath -NewName bar -ErrorAction Stop"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"},

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ Describe "Get-ChildItem" -Tags "CI" {
161161
(Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1
162162
}
163163

164-
It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows) {
164+
# VSTS machines don't have a page file
165+
It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Pending {
165166
# Don't remove!!! It is special test for hidden and opened file with exclusive lock.
166167
$file = Get-ChildItem -path "$env:SystemDrive\\pagefile.sys" -Hidden
167168
$file | Should not be $null

test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1

+7-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Describe "Test-Connection" -tags "CI" {
7979
}
8080

8181
# In VSTS, address is 0.0.0.0
82-
It "Force IPv4 with implicit PingOptions" -Skip:(Test-IsVstsLinux) {
82+
It "Force IPv4 with implicit PingOptions" -Skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
8383
$result = Test-Connection $realName -Count 1 -IPv4
8484

8585
$result.Replies[0].Address | Should -BeExactly $realAddress
@@ -90,7 +90,7 @@ Describe "Test-Connection" -tags "CI" {
9090
}
9191

9292
# In VSTS, address is 0.0.0.0
93-
It "Force IPv4 with explicit PingOptions" -Skip:(Test-IsVstsLinux) {
93+
It "Force IPv4 with explicit PingOptions" -Skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
9494
$result1 = Test-Connection $realName -Count 1 -IPv4 -MaxHops 10 -DontFragment
9595

9696
$result2 = Test-Connection $realName -Count 1 -IPv4 -MaxHops 1 -DontFragment
@@ -196,8 +196,9 @@ Describe "Test-Connection" -tags "CI" {
196196
}
197197

198198
# TODO: We skip the MTUSizeDetect tests on Unix because we expect 'TtlExpired' but get 'TimeOut' internally from .Net Core
199+
# Skipping on VSTS in Windows due to `TimedOut`
199200
Context "MTUSizeDetect" {
200-
It "MTUSizeDetect works" -Pending:(!$isWindows) {
201+
It "MTUSizeDetect works" -Pending:(!$isWindows -or (Test-IsVstsWindows)) {
201202
$result = Test-Connection $realName -MTUSizeDetect
202203

203204
$result | Should -BeOfType "System.Net.NetworkInformation.PingReply"
@@ -206,7 +207,7 @@ Describe "Test-Connection" -tags "CI" {
206207
$result.MTUSize | Should -BeGreaterThan 0
207208
}
208209

209-
It "Quiet works" -Pending:(!$isWindows) {
210+
It "Quiet works" -Pending:(!$isWindows -or (Test-IsVstsWindows)) {
210211
$result = Test-Connection $realName -MTUSizeDetect -Quiet
211212

212213
$result | Should -BeOfType "Int32"
@@ -216,7 +217,7 @@ Describe "Test-Connection" -tags "CI" {
216217

217218
Context "TraceRoute" {
218219
# Hangs in VSTS Linux
219-
It "TraceRoute works" -skip:(Test-IsVstsLinux) {
220+
It "TraceRoute works" -skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
220221
$result = Test-Connection $realName -TraceRoute
221222
$replies = $result.Replies
222223
# Check target host reply.
@@ -243,7 +244,7 @@ Describe "Test-Connection" -tags "CI" {
243244
}
244245

245246
# Hangs in VSTS Linux
246-
It "Quiet works" -skip:(Test-IsVstsLinux) {
247+
It "Quiet works" -skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
247248
$result = Test-Connection $realName -TraceRoute -Quiet
248249

249250
$result | Should -BeTrue

test/powershell/Modules/Microsoft.PowerShell.Security/FileCatalog.Tests.ps1

+10-2
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,24 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" {
226226
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
227227
}
228228

229-
It "NewFileCatalogFolderWhenCatalogFileIsCreatedInsideSameFolder" {
229+
# This is failing saying the exact thing that it says is supposed to work does not
230+
It "Test-FileCatalog should pass when catalog is in the same folder as files being tested" -Pending {
230231

231-
$catalogPath = "$env:TEMP\UserConfigProv\NewFileCatalogFolderWhenCatalogFileIsCreatedInsideSameFolder.cat"
232+
$catalogPath = "$env:TEMP\UserConfigProv\catalog.cat"
232233
try
233234
{
234235
copy-item "$testDataPath\UserConfigProv" $env:temp -Recurse -ErrorAction SilentlyContinue
235236
Push-Location "$env:TEMP\UserConfigProv"
236237
# When -Path is not specified, it should use current directory
237238
$null = New-FileCatalog -CatalogFilePath $catalogPath -CatalogVersion 1.0
238239
$result = Test-FileCatalog -CatalogFilePath $catalogPath
240+
241+
if($result -ne 'Valid')
242+
{
243+
# We will fail, Write why.
244+
$detailResult = Test-FileCatalog -CatalogFilePath $catalogPath -Detailed
245+
$detailResult | ConvertTo-Json | Write-Verbose -Verbose
246+
}
239247
}
240248
finally
241249
{

test/tools/Modules/HelpersCommon/HelpersCommon.psd1

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FunctionsToExport = @(
2626
'Test-IsElevated'
2727
'Test-IsRoot'
2828
'Test-IsVstsLinux'
29+
'Test-IsVstsWindows'
2930
'Test-TesthookIsSet'
3031
'Wait-FileToBePresent'
3132
'Wait-UntilTrue'

test/tools/Modules/HelpersCommon/HelpersCommon.psm1

+6
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,9 @@ function Test-IsVstsLinux
260260
{
261261
return ($env:TF_BUILD -and $IsLinux)
262262
}
263+
264+
# Tests if we are running is a VSTS Linux Build
265+
function Test-IsVstsWindows
266+
{
267+
return ($env:TF_BUILD -and $IsWindows)
268+
}

0 commit comments

Comments
 (0)