Files
PowerShell-PowerShell/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1
T
James Truher [MSFT] c97ca777df Jameswtruher/travisdailybuild (#2958)
* Stifle progress output in build.psm1 for some operations

Modify test failure presentation to use platform available XML methods

* Add timeout support for returning runtime parsing errors

Some of the language/parser tests have been hanging in a non-reproducable manner which
causes the CI system to invalidate the entire run. This change adds support for timeout
which will fail a test if it runs to long, rather than invalidate the entire run.

current behavior is still supported, and is not done in a new session:
PS> get-runtimeerror -src '1/'
At line:1 char:3
+ 1/
+   ~
You must provide a value expression following the '/' operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

Adding a timeout will do the operation in a async powershell session
PS> get-runtimeerror -src '1/' -timeout 5
You must provide a value expression following the '/' operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

If the operation takes longer than the supplied timeout, a timeout error will be returned
PS> get-runtimeerror -src 'start-sleep 6' -timeout 2
get-runtimeerror : Operation Timed Out ('start-sleep 6')
At line:1 char:1
+ get-runtimeerror -src 'start-sleep 6' -timeout 2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RuntimeError

* Modify native linux command tests to skip on Windows and pending on Mac

* remove verbose and progress output from help tests

* Be sure that Feature Counter tests only run on Windows

Also, only call add-type in CounterTestHelperFunctions.ps1 if we're going to actually run the tests

* do not run any get-computerinfo tests on non-windows systems

* suppress progress output from PowerShell Get tests

* remove -quiet from API and CRON Builds

Travis watches output from the build to ensure that it hasn't hung
we need to find a balance between too much output and not enough output.
A run which has too much output is killed because it looks like an error loop
A run which has too little output is killed because it looks like a hang

* Remove commented line in Import-Counter.Tests.ps1

Remove extraneous extra line in PowerShellGet.Tests.ps1

* Change `-as "type"` to `-as [type]` in build.psm1

Alter timeout to 10 seconds to be improve chances of not timing out for runtime parser checks
improve logic for counter tests to also skip for IoT

* use the existing function of SkipCounterTests rather than duplicate the logic in import-counter.tests.ps1
2017-01-10 14:42:27 -08:00

205 lines
7.2 KiB
PowerShell

# no progress output during these tests
$ProgressPreference = "SilentlyContinue"
$RepositoryName = 'INTGallery'
$SourceLocation = 'https://dtlgalleryint.cloudapp.net'
$RegisteredINTRepo = $false
$ContosoServer = 'ContosoServer'
$FabrikamServerScript = 'Fabrikam-ServerScript'
#region Utility functions
function IsInbox { $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase) }
function IsWindows { $PSVariable = Get-Variable -Name IsWindows -ErrorAction Ignore; return (-not $PSVariable -or $PSVariable.Value) }
function IsCoreCLR { $PSVariable = Get-Variable -Name IsCoreCLR -ErrorAction Ignore; return ($PSVariable -and $PSVariable.Value) }
#endregion
#region Install locations for modules and scripts
if(IsInbox)
{
$script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell"
}
else
{
$script:ProgramFilesPSPath = $PSHome
}
if(IsInbox)
{
try
{
$script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments")
}
catch
{
$script:MyDocumentsFolderPath = $null
}
$script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath)
{
Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell"
}
else
{
Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell"
}
}
elseif(IsWindows)
{
$script:MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath 'Documents\PowerShell'
}
else
{
$script:MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath '.local/share/powershell'
}
$script:ProgramFilesModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Modules'
$script:MyDocumentsModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Modules'
$script:ProgramFilesScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Scripts'
$script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Scripts'
#endregion
#region Register a test repository
# Check if the PackageManagement works in the base-oS or PowerShellCore
$PSHome
$PSVersionTable
$env:PSModulePath
Get-Module -ListAvailable -Name PackageManagement, PowerShellGet
Import-Module PackageManagement -force -verbose
Get-PackageProvider -ListAvailable
$repo = Get-PSRepository -ErrorAction SilentlyContinue |
Where-Object {$_.SourceLocation.StartsWith($SourceLocation, [System.StringComparison]::OrdinalIgnoreCase)}
if($repo)
{
$RepositoryName = $repo.Name
}
else
{
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
$RegisteredINTRepo = $true
}
#endregion
function Remove-InstalledModules
{
Get-InstalledModule -Name $ContosoServer -AllVersions -ErrorAction SilentlyContinue | Uninstall-Module -Force
}
Describe "PowerShellGet - Module tests" -tags "Feature" {
BeforeEach {
Remove-InstalledModules
}
It "Should find a module correctly" {
$psgetModuleInfo = Find-Module -Name $ContosoServer -Repository $RepositoryName
$psgetModuleInfo.Name | Should Be $ContosoServer
$psgetModuleInfo.Repository | Should Be $RepositoryName
}
It "Should install a module correctly to the required location with CurrentUser scope" {
Install-Module -Name $ContosoServer -Repository $RepositoryName -Scope CurrentUser
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
$installedModuleInfo | Should Not Be $null
$installedModuleInfo.Name | Should Be $ContosoServer
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
$module = Get-Module $ContosoServer -ListAvailable
$module.Name | Should be $ContosoServer
$module.ModuleBase | Should Be $installedModuleInfo.InstalledLocation
}
AfterAll {
Remove-InstalledModules
}
}
Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdminOnWindows') {
BeforeEach {
Remove-InstalledModules
}
It "Should install a module correctly to the required location with default AllUsers scope" {
Install-Module -Name $ContosoServer -Repository $RepositoryName
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
$installedModuleInfo | Should Not Be $null
$installedModuleInfo.Name | Should Be $ContosoServer
$installedModuleInfo.InstalledLocation.StartsWith($script:programFilesModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
$module = Get-Module $ContosoServer -ListAvailable
$module.Name | Should be $ContosoServer
$module.ModuleBase | Should Be $installedModuleInfo.InstalledLocation
}
AfterAll {
Remove-InstalledModules
}
}
function Remove-InstalledScripts
{
Get-InstalledScript -Name $FabrikamServerScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
}
Describe "PowerShellGet - Script tests" -tags "Feature" {
BeforeEach {
Remove-InstalledScripts
}
It "Should find a script correctly" {
$psgetScriptInfo = Find-Script -Name $FabrikamServerScript -Repository $RepositoryName
$psgetScriptInfo.Name | Should Be $FabrikamServerScript
$psgetScriptInfo.Repository | Should Be $RepositoryName
}
It "Should install a script correctly to the required location with CurrentUser scope" {
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -Scope CurrentUser -NoPathUpdate
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
$installedScriptInfo | Should Not Be $null
$installedScriptInfo.Name | Should Be $FabrikamServerScript
$installedScriptInfo.InstalledLocation.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
}
AfterAll {
Remove-InstalledScripts
}
}
Describe "PowerShellGet - Script tests (Admin)" -tags @('Feature', 'RequireAdminOnWindows') {
BeforeEach {
Remove-InstalledScripts
}
It "Should install a script correctly to the required location with default AllUsers scope" {
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
$installedScriptInfo | Should Not Be $null
$installedScriptInfo.Name | Should Be $FabrikamServerScript
$installedScriptInfo.InstalledLocation.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
}
AfterAll {
Remove-InstalledScripts
}
}
if($RegisteredINTRepo)
{
Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | Unregister-PSRepository
}