Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ CHANGELOG.md merge=union
* text=auto
*.png binary
*.rtf binary
testablescript.ps1 text eol=lf
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these two?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just forcing the line endings to be LF which is what we expect

TestFileCatalog.txt text eol=lf
65 changes: 65 additions & 0 deletions .vsts-ci/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
queue:
name: Hosted VS2017
parallel: 2 # Limit to two agents at a time
matrix:
UnelevatedPesterTests:
Purpose: UnelevatedPesterTests
ElevatedPesterTests_xUnit_Packaging:
Purpose: ElevatedPesterTests_xUnit_Packaging

variables:
GIT_CONFIG_PARAMETERS: "'core.autocrlf=false'"
DOTNET_CLI_TELEMETRY_OPTOUT: 1
POWERSHELL_TELEMETRY_OPTOUT: 1
# Avoid expensive initialization of dotnet cli, see: http://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1

resources:
- repo: self
clean: true

steps:
- powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))"
displayName: Set Build Name for Non-PR
condition: ne(variables['Build.Reason'], 'PullRequest')

- powershell: |
git submodule update --init
displayName: SubModule Init
condition: succeededOrFailed()

- powershell: |
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-evaluate if this is needed

Import-Module .\tools\Appveyor.psm1
Invoke-AppveyorInstall
displayName: Bootstrap
condition: succeededOrFailed()

- powershell: |
Import-Module .\tools\Appveyor.psm1
Invoke-AppveyorBuild
Save-PSOptions
displayName: Build
condition: succeeded()

- powershell: |
Import-Module .\tools\Appveyor.psm1
Restore-PSOptions
Invoke-AppveyorTest -Purpose '$(Purpose)'
displayName: Test
condition: succeeded()

- powershell: |
Import-Module .\tools\Appveyor.psm1
Restore-PSOptions
Invoke-AppveyorAfterTest
displayName: AfterTest
condition: succeededOrFailed()

- powershell: |
Import-Module .\tools\Appveyor.psm1
Restore-PSOptions
Invoke-AppveyorFinish
displayName: Finish
condition: eq(variables['Purpose'], 'ElevatedPesterTests_xUnit_Packaging')
116 changes: 106 additions & 10 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ function Get-EnvironmentInformation
if ($Environment.IsWindows)
{
$environment += @{'IsAdmin' = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)}
# Can't use $env:HOME - not available on older systems (e.g. in AppVeyor)
$environment += @{'nugetPackagesRoot' = "${env:HOMEDRIVE}${env:HOMEPATH}\.nuget\packages"}
$environment += @{'nugetPackagesRoot' = "${env:USERPROFILE}\.nuget\packages"}
}
else
{
Expand Down Expand Up @@ -876,14 +875,15 @@ function New-PSOptions {
$RootInfo['IsValid'] = $true
}

return @{ RootInfo = [PSCustomObject]$RootInfo
Top = $Top
Configuration = $Configuration
Framework = $Framework
Runtime = $Runtime
Output = $Output
CrossGen = $CrossGen.IsPresent
PSModuleRestore = $PSModuleRestore.IsPresent }
return New-PSOptionsObject `
-RootInfo ([PSCustomObject]$RootInfo) `
-Top $Top `
-Runtime $Runtime `
-Crossgen $Crossgen.IsPresent `
-Configuration $Configuration `
-PSModuleRestore $PSModuleRestore.IsPresent `
-Framework $Framework `
-Output $Output
}

# Get the Options of the last build
Expand Down Expand Up @@ -2996,6 +2996,102 @@ function Restore-PSOptions {
Set-PSOptions -Options $options
}

# Save PSOptions to be restored by Restore-PSOptions
function Save-PSOptions {
param(
[ValidateScript({$parent = Split-Path $_;if($parent){Test-Path $parent}else{return $true}})]
[ValidateNotNullOrEmpty()]
[string]
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),

[ValidateNotNullOrEmpty()]
[object]
$Options = (Get-PSOptions -DefaultToNew)
)

$Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath $PSOptionsPath
}

# Restore PSOptions
# Optionally remove the PSOptions file
function Restore-PSOptions {
param(
[ValidateScript({Test-Path $_})]
[string]
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),
[switch]
$Remove
)

$options = Get-Content -Path $PSOptionsPath | ConvertFrom-Json

if($Remove)
{
# Remove PSOptions.
# The file is only used to set the PSOptions.
Remove-Item -Path $psOptionsPath -Force
}

$newOptions = New-PSOptionsObject `
-RootInfo $options.RootInfo `
-Top $options.Top `
-Runtime $options.Runtime `
-Crossgen $options.Crossgen `
-Configuration $options.Configuration `
-PSModuleRestore $options.PSModuleRestore `
-Framework $options.Framework `
-Output $options.Output

Set-PSOptions -Options $newOptions
}

function New-PSOptionsObject
{
param(
[PSCustomObject]
$RootInfo,

[Parameter(Mandatory)]
[String]
$Top,

[Parameter(Mandatory)]
[String]
$Runtime,

[Parameter(Mandatory)]
[Bool]
$CrossGen,

[Parameter(Mandatory)]
[String]
$Configuration,

[Parameter(Mandatory)]
[Bool]
$PSModuleRestore,

[Parameter(Mandatory)]
[String]
$Framework,

[Parameter(Mandatory)]
[String]
$Output
)

return @{
RootInfo = $RootInfo
Top = $Top
Configuration = $Configuration
Framework = $Framework
Runtime = $Runtime
Output = $Output
CrossGen = $CrossGen
PSModuleRestore = $PSModuleRestore
}
}

$script:RESX_TEMPLATE = @'
<?xml version="1.0" encoding="utf-8"?>
<root>
Expand Down
8 changes: 4 additions & 4 deletions test/powershell/Modules/CimCmdlets/CimSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
$PSDefaultParameterValues['it:pending'] = $true
}

Describe "New-CimSession" -Tag @("CI") {
Describe "New-CimSession" -Tag @("CI","RequireAdminOnWindows") {
BeforeAll {
$sessions = @()
}
Expand All @@ -16,15 +16,15 @@ try {
}

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

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

It "A cim session can be removed" {
$sessionName = [guid]::NewGuid()
$sessionName = [guid]::NewGuid().Guid
$session = New-CimSession -ComputerName . -Name $sessionName
$sessions += $session
$session.Name | Should -BeExactly $sessionName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
$commandInfo = Get-Command Get-Date -ShowCommandInfo
}

It "Test wildcard with drive relative directory path" {
# this test doesn't test anything on non-windows platforms
It "Test wildcard with drive relative directory path" -Skip:(!$IsWindows) {
$pathName = Join-Path $TestDrive "WildCardCommandA*"
$driveOffset = $pathName.IndexOf(":")
$pathName = $pathName.Substring($driveOffset + 1)
$result = Get-Command -Name $pathName
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be WildCardCommandA.exe
$driveName = $pathName.Substring(0,$driveOffset + 1)
Push-Location -Path $driveName
try {
$pathName = $pathName.Substring($driveOffset + 1)
$result = Get-Command -Name $pathName
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be WildCardCommandA.exe
}
catch {
Pop-Location
}
}

It "Test wildcard with relative directory path" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {

It "Access-denied test for <cmdline>" -Skip:(-not $IsWindows) -TestCases @(
# NOTE: ensure the fileNameBase parameter is unique for each test case; it is used to generate a unique error and done file name.
@{cmdline = "Get-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"}
# The following test does not consistently work on windows
# @{cmdline = "Get-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"}
@{cmdline = "Get-ChildItem $protectedPath -ErrorAction Stop"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"}
@{cmdline = "New-Item -Type File -Path $newItemPath -ErrorAction Stop"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"}
@{cmdline = "Rename-Item -Path $protectedPath -NewName bar -ErrorAction Stop"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ Describe "Get-ChildItem" -Tags "CI" {
(Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1
}

It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows) {
# VSTS machines don't have a page file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at all or on system drive?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't have a page file on the system drive

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could find the page file location:

			#Open the registry on multiple remote computers
			$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$server )
			$RegKeyPath= "SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
			$pageFileKey=$reg.OpenSubKey($RegKeyPath)
			$pageFileLocation=$pageFileKey.GetValue("ExistingPageFiles")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated #7554

It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Pending {
# Don't remove!!! It is special test for hidden and opened file with exclusive lock.
$file = Get-ChildItem -path "$env:SystemDrive\\pagefile.sys" -Hidden
$file | Should not be $null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Describe "Test-Connection" -tags "CI" {
}

# In VSTS, address is 0.0.0.0
It "Force IPv4 with implicit PingOptions" -Skip:(Test-IsVstsLinux) {
It "Force IPv4 with implicit PingOptions" -Skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how we'll do remoting tests if VSTS, address is 0.0.0.0?

What about web cmdlet tests? Seems we need add [Feature] to a commit title.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoting tests are working

Copy link
Copy Markdown
Member Author

@TravisEz13 TravisEz13 Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, only CI has been ported, not Feature tests. We should have a later pull request to enable daily builds and [Feature] etc

$result = Test-Connection $realName -Count 1 -IPv4

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

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

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

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

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

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

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

Context "TraceRoute" {
# Hangs in VSTS Linux
It "TraceRoute works" -skip:(Test-IsVstsLinux) {
It "TraceRoute works" -skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) {
$result = Test-Connection $realName -TraceRoute
$replies = $result.Replies
# Check target host reply.
Expand All @@ -243,7 +244,7 @@ Describe "Test-Connection" -tags "CI" {
}

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

$result | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,24 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" {
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
}

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

$catalogPath = "$env:TEMP\UserConfigProv\NewFileCatalogFolderWhenCatalogFileIsCreatedInsideSameFolder.cat"
$catalogPath = "$env:TEMP\UserConfigProv\catalog.cat"
try
{
copy-item "$testDataPath\UserConfigProv" $env:temp -Recurse -ErrorAction SilentlyContinue
Push-Location "$env:TEMP\UserConfigProv"
# When -Path is not specified, it should use current directory
$null = New-FileCatalog -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -CatalogFilePath $catalogPath

if($result -ne 'Valid')
{
# We will fail, Write why.
$detailResult = Test-FileCatalog -CatalogFilePath $catalogPath -Detailed
$detailResult | ConvertTo-Json | Write-Verbose -Verbose
}
}
finally
{
Expand Down
1 change: 1 addition & 0 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FunctionsToExport = @(
'Test-IsElevated'
'Test-IsRoot'
'Test-IsVstsLinux'
'Test-IsVstsWindows'
'Test-TesthookIsSet'
'Wait-FileToBePresent'
'Wait-UntilTrue'
Expand Down
6 changes: 6 additions & 0 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ function Test-IsVstsLinux
{
return ($env:TF_BUILD -and $IsLinux)
}

# Tests if we are running is a VSTS Linux Build
function Test-IsVstsWindows
{
return ($env:TF_BUILD -and $IsWindows)
}
Loading