2018-02-13 09:23:53 -08:00
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
2019-04-04 23:01:01 -07:00
Import-Module HelpersCommon
2016-10-17 12:04:37 -07:00
# Test Settings:
# This is the list of PowerShell Core modules for which we test update-help
$powershellCoreModules = @ (
"CimCmdlets"
2016-12-02 15:32:03 -08:00
<#
This scenario is broken due to issue # https://github.com/PowerShell/platyPS/issues/241
Re-enable when issue is fixed.
2016-10-17 12:04:37 -07:00
"Microsoft.PowerShell.Archive"
2016-12-02 15:32:03 -08:00
#>
2016-10-17 12:04:37 -07:00
"Microsoft.PowerShell.Host"
"Microsoft.PowerShell.Core"
"Microsoft.PowerShell.Diagnostics"
"Microsoft.PowerShell.Management"
2017-07-19 17:20:35 -07:00
# "Microsoft.PowerShell.LocalAccounts" removed due to #4274
2016-10-17 12:04:37 -07:00
"Microsoft.PowerShell.Security"
"Microsoft.PowerShell.Utility"
"Microsoft.WsMan.Management"
"PackageManagement"
# "PowershellGet"
)
# The file extension for the help content on the Download Center.
# For Linux we use zip, and on Windows we use $extension.
$extension = ".zip"
if ([ System.Management.Automation.Platform ]:: IsWindows )
{
$extension = ".cab"
}
2018-04-02 15:32:55 -07:00
if ([ System.Management.Automation.Platform ]:: IsWindows )
{
$userHelpRoot = Join-Path $HOME "Documents/PowerShell/Help/"
}
else
{
$userModulesRoot = [ System.Management.Automation.Platform ]:: SelectProductNameForDirectory ([ System . Management . Automation . Platform + XDG_Type ]:: USER_MODULES )
$userHelpRoot = Join-Path $userModulesRoot -ChildPath ".." -AdditionalChildPath "Help"
}
2016-10-17 12:04:37 -07:00
# This is the list of test cases -- each test case represents a PowerShell Core module.
$testCases = @ {
"CimCmdlets" = @ {
HelpFiles = "Microsoft.Management.Infrastructure.CimCmdlets.dll-help.xml"
HelpInfoFiles = "CimCmdlets_fb6cc51d-c096-4b38-b78d-0fed6277096a_HelpInfo.xml"
CompressedFiles = "CimCmdlets_fb6cc51d-c096-4b38-b78d-0fed6277096a_en-US_HelpContent $extension "
HelpInstallationPath = " $pshome \Modules\CimCmdlets\en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \CimCmdlets\en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Archive" = @ {
2018-11-30 09:49:32 -08:00
HelpFiles = "Microsoft.PowerShell.Archive-help.xml"
2016-10-17 12:04:37 -07:00
HelpInfoFiles = "Microsoft.PowerShell.Archive_eb74e8da-9ae2-482a-a648-e96550fb8733_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Archive_eb74e8da-9ae2-482a-a648-e96550fb8733_en-US_HelpContent $extension "
HelpInstallationPath = " $pshome \Modules\Microsoft.PowerShell.Archive\en-US"
}
"Microsoft.PowerShell.Core" = @ {
HelpFiles = "System.Management.Automation.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Core_00000000-0000-0000-0000-000000000000_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Core_00000000-0000-0000-0000-000000000000_en-US_HelpContent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Diagnostics" = @ {
HelpFiles = "Microsoft.PowerShell.Commands.Diagnostics.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Diagnostics_ca046f10-ca64-4740-8ff9-2565dba61a4f_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Diagnostics_ca046f10-ca64-4740-8ff9-2565dba61a4f_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Host" = @ {
HelpFiles = "Microsoft.PowerShell.ConsoleHost.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Host_56d66100-99a0-4ffc-a12d-eee9a6718aef_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Host_56d66100-99a0-4ffc-a12d-eee9a6718aef_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.LocalAccounts" = @ {
HelpFiles = "Microsoft.Powershell.LocalAccounts.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.LocalAccounts_8e362604-2c0b-448f-a414-a6a690a644e2_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.LocalAccounts_8e362604-2c0b-448f-a414-a6a690a644e2_en-US_HelpContent $extension "
HelpInstallationPath = " $pshome \Modules\Microsoft.PowerShell.LocalAccounts\en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \Microsoft.PowerShell.LocalAccounts\en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Management" = @ {
HelpFiles = "Microsoft.PowerShell.Commands.Management.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Management_eefcb906-b326-4e99-9f54-8b4bb6ef3c6d_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Management_eefcb906-b326-4e99-9f54-8b4bb6ef3c6d_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Security" = @ {
HelpFiles = "Microsoft.PowerShell.Security.dll-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Security_a94c8c7e-9810-47c0-b8af-65089c13a35a_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Security_a94c8c7e-9810-47c0-b8af-65089c13a35a_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.PowerShell.Utility" = @ {
HelpFiles = "Microsoft.PowerShell.Commands.Utility.dll-Help.xml" , "Microsoft.PowerShell.Utility-help.xml"
HelpInfoFiles = "Microsoft.PowerShell.Utility_1da87e53-152b-403e-98dc-74d7b4d63d59_HelpInfo.xml"
CompressedFiles = "Microsoft.PowerShell.Utility_1da87e53-152b-403e-98dc-74d7b4d63d59_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"Microsoft.WSMan.Management" = @ {
HelpFiles = "Microsoft.WSMan.Management.dll-help.xml"
HelpInfoFiles = "Microsoft.WsMan.Management_766204A6-330E-4263-A7AB-46C87AFC366C_HelpInfo.xml"
CompressedFiles = "Microsoft.WsMan.Management_766204A6-330E-4263-A7AB-46C87AFC366C_en-US_helpcontent $extension "
HelpInstallationPath = " $pshome \en-US"
2018-04-02 15:32:55 -07:00
HelpInstallationPathHome = " $userHelpRoot \en-US"
2016-10-17 12:04:37 -07:00
}
"PackageManagement" = @ {
HelpFiles = "Microsoft.PowerShell.PackageManagement.dll-help.xml"
HelpInfoFiles = "PackageManagement_4ae9fd46-338a-459c-8186-07f910774cb8_HelpInfo.xml"
CompressedFiles = "PackageManagement_4ae9fd46-338a-459c-8186-07f910774cb8_en-US_helpcontent $extension "
2018-08-14 10:15:05 -07:00
HelpInstallationPath = " $pshome \Modules\PackageManagement\en-US"
HelpInstallationPathHome = " $userHelpRoot \PackageManagement\en-US"
2016-10-17 12:04:37 -07:00
}
"PowershellGet" = @ {
HelpFiles = "PSGet.psm1-help.xml"
HelpInfoFiles = "PowershellGet_1d73a601-4a6c-43c5-ba3f-619b18bbb404_HelpInfo.xml"
CompressedFiles = "PowershellGet_1d73a601-4a6c-43c5-ba3f-619b18bbb404_en-US_helpcontent $extension "
2018-08-14 10:15:05 -07:00
HelpInstallationPath = " $pshome \Modules\PowershellGet\en-US"
HelpInstallationPathHome = " $userHelpRoot \PackageManagement\en-US"
2016-10-17 12:04:37 -07:00
}
}
# These are the inbox modules.
$modulesInBox = @ ( "Microsoft.PowerShell.Core"
Get-Module -ListAvailable | ForEach-Object { $_ . Name }
)
function GetFiles
{
param (
[ string ] $fileType = "*help.xml" ,
[ ValidateNotNullOrEmpty ()]
[ string ] $path
)
2016-12-06 13:58:57 -08:00
2018-05-17 14:42:04 -07:00
Get-ChildItem $path -Include $fileType -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
2016-10-17 12:04:37 -07:00
}
function ValidateInstalledHelpContent
{
param (
[ ValidateNotNullOrEmpty ()]
2018-04-02 15:32:55 -07:00
[ string ] $moduleName ,
[ switch ] $UserScope
2016-10-17 12:04:37 -07:00
)
2018-04-02 15:32:55 -07:00
if ( $UserScope )
{
$params = @ { Path = $testCases [ $moduleName ]. HelpInstallationPathHome }
}
else
{
$params = @ { Path = $testCases [ $moduleName ]. HelpInstallationPath }
}
$helpFilesInstalled = @ ( GetFiles @params | ForEach-Object { Split-Path $_ -Leaf })
2016-10-17 12:04:37 -07:00
$expectedHelpFiles = @ ( $testCases [ $moduleName ]. HelpFiles )
2018-03-14 12:13:32 -07:00
$helpFilesInstalled . Count | Should -Be $expectedHelpFiles . Count
2016-10-17 12:04:37 -07:00
foreach ( $fileName in $expectedHelpFiles )
{
2018-03-14 12:13:32 -07:00
$helpFilesInstalled -contains $fileName | Should -BeTrue
2016-10-17 12:04:37 -07:00
}
}
function RunUpdateHelpTests
{
param (
[ string ] $tag = "CI" ,
2018-04-02 15:32:55 -07:00
[ switch ] $useSourcePath ,
[ switch ] $userscope
2016-10-17 12:04:37 -07:00
)
foreach ( $moduleName in $modulesInBox )
{
if ( $powershellCoreModules -contains $moduleName )
{
2019-04-04 23:01:01 -07:00
It "Validate Update-Help for module ' $moduleName ' with scope as ' $userscope '" -Skip: (!( Test-CanWriteToPsHome ) -and $userscope -eq $false ) {
2018-04-02 15:32:55 -07:00
if ( $userscope )
{
$params = @ { Path = $testCases [ $moduleName ]. HelpInstallationPathHome }
$updateScope = @ { Scope = 'CurrentUser' }
}
else
{
$params = @ { Path = $testCases [ $moduleName ]. HelpInstallationPath }
$updateScope = @ { Scope = 'AllUsers' }
}
$commonParam = @ {
Include = @ ( "*help.xml" )
Recurse = $true
ErrorAction = 'SilentlyContinue'
}
$params += $commonParam
2016-10-17 12:04:37 -07:00
# If the help file is already installed, delete it.
2018-04-02 15:32:55 -07:00
Get-ChildItem @params |
2016-10-17 12:04:37 -07:00
Remove-Item -Force -ErrorAction SilentlyContinue
if (( Get-UICulture ). Name -ne "en-Us" )
{
if ( $useSourcePath )
{
2018-04-02 15:32:55 -07:00
Update-Help -Module $moduleName -Force -UICulture en-US -SourcePath " $PSScriptRoot \assets" @updateScope
2016-10-17 12:04:37 -07:00
}
else
{
2018-04-02 15:32:55 -07:00
Update-Help -Module $moduleName -Force -UICulture en-US @updateScope
2016-10-17 12:04:37 -07:00
}
}
else
{
if ( $useSourcePath )
{
2018-04-02 15:32:55 -07:00
Update-Help -Module $moduleName -Force -SourcePath " $PSScriptRoot \assets" @updateScope
2016-10-17 12:04:37 -07:00
}
else
{
2018-04-02 15:32:55 -07:00
Update-Help -Module $moduleName -Force @updateScope
2016-10-17 12:04:37 -07:00
}
}
2018-04-02 15:32:55 -07:00
if ( $userscope )
{
ValidateInstalledHelpContent -moduleName $moduleName -UserScope
}
else
{
ValidateInstalledHelpContent -moduleName $moduleName
}
2016-10-17 12:04:37 -07:00
}
if ( $tag -eq "CI" )
{
break
}
}
}
}
function RunSaveHelpTests
{
param (
2018-03-02 13:17:05 -08:00
[ string ] $tag = "CI"
2016-10-17 12:04:37 -07:00
)
foreach ( $moduleName in $modulesInBox )
{
if ( $powershellCoreModules -contains $moduleName )
{
try
{
$saveHelpFolder = Join-Path $TestDrive ( Get-Random ). ToString ()
2018-04-02 14:07:02 -07:00
New-Item $saveHelpFolder -Force -ItemType Directory > $null
2016-10-17 12:04:37 -07:00
2018-04-02 14:07:02 -07:00
## Save help has intermittent connectivity issues for downloading PackageManagement help content.
## Hence the test has been marked as Pending.
if ( $moduleName -eq 'PackageManagement' )
{
$pending = $true
}
It "Validate Save-Help for the ' $moduleName ' module" -Pending: $pending {
2016-10-17 12:04:37 -07:00
if (( Get-UICulture ). Name -ne "en-Us" )
{
Save-Help -Module $moduleName -Force -UICulture en-US -DestinationPath $saveHelpFolder
}
else
{
Save-Help -Module $moduleName -Force -DestinationPath $saveHelpFolder
}
ValidateSaveHelp -moduleName $moduleName -path $saveHelpFolder
}
2018-04-02 14:07:02 -07:00
## Reset pending state.
if ( $pending )
{
$pending = $false
}
2016-10-17 12:04:37 -07:00
if ( $tag -eq "CI" )
{
break
}
}
finally
{
2018-05-17 14:42:04 -07:00
Remove-Item $saveHelpFolder -Force -ErrorAction SilentlyContinue -Recurse
2016-10-17 12:04:37 -07:00
}
}
}
}
function ValidateSaveHelp
{
param (
[ string ] $moduleName ,
[ string ] $path
)
2017-07-22 05:03:49 +01:00
$compressedFile = GetFiles -fileType "* $extension " -path $path | ForEach-Object { Split-Path $_ -Leaf }
2016-10-17 12:04:37 -07:00
$expectedCompressedFile = $testCases [ $moduleName ]. CompressedFiles
2019-04-16 14:14:29 -07:00
$expectedCompressedFile | Should -Not -BeNullOrEmpty -Because "Test data (expectedCompressedFile) should never be null"
$compressedFile | Should -Be $expectedCompressedFile -Because "Save-Help for $module should download ' $expectedCompressedFile '"
2016-10-17 12:04:37 -07:00
2017-07-22 05:03:49 +01:00
$helpInfoFile = GetFiles -fileType "*HelpInfo.xml" -path $path | ForEach-Object { Split-Path $_ -Leaf }
2016-10-17 12:04:37 -07:00
$expectedHelpInfoFile = $testCases [ $moduleName ]. HelpInfoFiles
2019-04-16 14:14:29 -07:00
$expectedHelpInfoFile | Should -Not -BeNullOrEmpty -Because "Test data (expectedHelpInfoFile) should never be null"
$helpInfoFile | Should -Be $expectedHelpInfoFile -Because "Save-Help for $module should download ' $expectedHelpInfoFile '"
2016-10-17 12:04:37 -07:00
}
2018-02-26 12:35:05 -08:00
Describe "Validate Update-Help from the Web for one PowerShell Core module." -Tags @ ( 'CI' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2016-10-17 12:04:37 -07:00
2018-04-02 15:32:55 -07:00
RunUpdateHelpTests -tag "CI" -Scope 'AllUsers'
}
Describe "Validate Update-Help from the Web for one PowerShell Core module for user scope." -Tags @ ( 'CI' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunUpdateHelpTests -tag "CI" -Scope 'CurrentUser'
2016-10-17 12:04:37 -07:00
}
2018-02-26 12:35:05 -08:00
Describe "Validate Update-Help from the Web for all PowerShell Core modules." -Tags @ ( 'Feature' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2016-10-17 12:04:37 -07:00
2018-04-02 15:32:55 -07:00
RunUpdateHelpTests -tag "Feature" -Scope 'AllUsers'
}
Describe "Validate Update-Help from the Web for all PowerShell Core modules for user scope." -Tags @ ( 'Feature' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunUpdateHelpTests -tag "Feature" -Scope 'CurrentUser'
2016-10-17 12:04:37 -07:00
}
2018-02-26 12:35:05 -08:00
Describe "Validate Update-Help -SourcePath for one PowerShell Core module." -Tags @ ( 'CI' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2016-10-17 12:04:37 -07:00
2018-04-02 15:32:55 -07:00
RunUpdateHelpTests -tag "CI" -useSourcePath -Scope 'AllUsers'
}
Describe "Validate Update-Help -SourcePath for one PowerShell Core module for user scope." -Tags @ ( 'CI' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunUpdateHelpTests -tag "CI" -useSourcePath -Scope 'CurrentUser'
2016-10-17 12:04:37 -07:00
}
2018-02-26 12:35:05 -08:00
Describe "Validate Update-Help -SourcePath for all PowerShell Core modules." -Tags @ ( 'Feature' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2016-10-17 12:04:37 -07:00
2018-04-02 15:32:55 -07:00
RunUpdateHelpTests -tag "Feature" -useSourcePath -Scope 'AllUsers'
}
Describe "Validate Update-Help -SourcePath for all PowerShell Core modules for user scope." -Tags @ ( 'Feature' , 'RequireAdminOnWindows' , 'RequireSudoOnUnix' ) {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunUpdateHelpTests -tag "Feature" -useSourcePath -Scope 'CurrentUser'
2016-10-17 12:04:37 -07:00
}
Describe "Validate 'Save-Help -DestinationPath for one PowerShell Core modules." -Tags @ ( 'CI' , 'RequireAdminOnWindows' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2018-03-02 13:17:05 -08:00
RunSaveHelpTests -tag "CI"
2016-10-17 12:04:37 -07:00
}
Describe "Validate 'Save-Help -DestinationPath for all PowerShell Core modules." -Tags @ ( 'Feature' , 'RequireAdminOnWindows' ) {
2016-12-06 13:58:57 -08:00
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
2016-10-17 12:04:37 -07:00
RunSaveHelpTests -tag "Feature"
}