From ff8311ec60f6c6e8ee5681ec583c2d849a5df293 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 7 Jun 2022 10:39:13 -0700 Subject: [PATCH] Backport test fixes for 7.2 (#17494) --- .../Test-Connection.Tests.ps1 | 11 ++----- .../engine/Remoting/PSSession.Tests.ps1 | 10 ++---- .../Remoting/RemoteSession.Basic.Tests.ps1 | 33 ++++--------------- .../Modules/HelpersCommon/HelpersCommon.psd1 | 1 + .../Modules/HelpersCommon/HelpersCommon.psm1 | 14 ++++++++ 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 index 7addac6dc619..5173e0a68bb9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -96,15 +96,8 @@ Describe "Test-Connection" -tags "CI" { { Test-Connection "fakeHost" -Count 1 -ErrorAction Stop } | Should -Throw -ErrorId "TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand" # Error code = 11001 - Host not found. - $platform = Get-PlatformInfo - if ($platform.Platform -match "raspbian" -or ( $platform.Platform -match 'ubuntu' -and $platform.Version -eq '20.04')) { - $code = 11 - } elseif (!$IsWindows) { - $code = -131073 - } else { - $code = 11001 - } - $error[0].Exception.InnerException.ErrorCode | Should -Be $code + # Error code = -131073 - Invalid address + $error[0].Exception.InnerException.ErrorCode | Should -BeIn 11, -131073, 11001 } It "Force IPv4 with implicit PingOptions" { diff --git a/test/powershell/engine/Remoting/PSSession.Tests.ps1 b/test/powershell/engine/Remoting/PSSession.Tests.ps1 index 25c7ab9c5823..cbf7313eed02 100644 --- a/test/powershell/engine/Remoting/PSSession.Tests.ps1 +++ b/test/powershell/engine/Remoting/PSSession.Tests.ps1 @@ -79,14 +79,8 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS It "" -TestCases $testCases { param ($scriptBlock, $expectedErrorCode) - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index d56ed1999acc..84e25a276ecb 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -10,15 +10,8 @@ function GetRandomString() Describe "New-PSSession basic test" -Tag @("CI") { It "New-PSSession should not crash powershell" { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } @@ -29,15 +22,8 @@ Describe "New-PSSession basic test" -Tag @("CI") { Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { It "New-PSSession should throw when specifying Basic Auth over HTTP on Unix" -Skip:($IsWindows) { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } @@ -53,15 +39,8 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { # Skip this test for macOS because the latest OS release is incompatible with our shipped libmi for WinRM/OMI. It "New-PSSession should NOT throw a ConnectFailed exception when specifying Basic Auth over HTTPS on Unix" -Skip:($IsWindows) { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index 3d501983806f..43d2ada88ccc 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -35,6 +35,7 @@ FunctionsToExport = @( 'Wait-FileToBePresent' 'Wait-UntilTrue' 'Get-PlatformInfo' + 'Get-WSManSupport' ) CmdletsToExport= @() diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 894a85ff14d8..9e5510e0e82c 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -388,3 +388,17 @@ function Get-PlatformInfo { return "unknown" } } + +# return true if WsMan is supported on the current platform +function Get-WsManSupport { + $platformInfo = Get-PlatformInfo + if (($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '18.04') -or + ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '7') -or + $IsWindows + ) + { + return $true + } + + return $false +}