From 9117143ac2ab4cbb47f8beeb7393651ca1510b07 Mon Sep 17 00:00:00 2001 From: James Truher Date: Wed, 21 Aug 2019 14:28:50 -0700 Subject: [PATCH 1/3] changes for validation on alpine --- test/powershell/Host/Startup.Tests.ps1 | 5 +++++ .../Test-Connection.Tests.ps1 | 7 ++++++- .../Get-Date.Tests.ps1 | 7 ++++++- .../MOF-Compilation.Tests.ps1 | 11 ++++++----- .../engine/Remoting/PSSession.Tests.ps1 | 5 +++++ .../Remoting/RemoteSession.Basic.Tests.ps1 | 15 +++++++++++++++ .../Modules/HelpersCommon/HelpersCommon.psm1 | 18 ++++++++++++++++++ 7 files changed, 61 insertions(+), 7 deletions(-) diff --git a/test/powershell/Host/Startup.Tests.ps1 b/test/powershell/Host/Startup.Tests.ps1 index 41c1749c575..6fb2b7336ac 100644 --- a/test/powershell/Host/Startup.Tests.ps1 +++ b/test/powershell/Host/Startup.Tests.ps1 @@ -103,6 +103,11 @@ Describe "Validate start of console host" -Tag CI { } It "No new assemblies are loaded" { + if ( (Get-PlatformInfo) -eq "alpine" ) { + Set-ItResult -Pending -Because "Missing MI library causes list to be different" + return + } + $diffs = Compare-Object -ReferenceObject $allowedAssemblies -DifferenceObject $loadedAssemblies if ($null -ne $diffs) { 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 a4a2c14433f..15bd53bf495 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -108,7 +108,12 @@ Describe "Test-Connection" -tags "CI" { # After .Net Core fix we should have 'DontFragment | Should -Be $true' here. $result1.Replies[0].Options.Ttl | Should -BeLessOrEqual 128 if (!$isWindows) { - $result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty + if ( (Get-PlatformInfo) -eq "alpine" ) { + $result1.Replies[0].Options.DontFragment | Should -Be $true + } + else { + $result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty + } # depending on the network configuration any of the following should be returned $result2.Replies[0].Status | Should -BeIn "TtlExpired","TimedOut","Success" } else { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index 1d66eb66ed5..668eab407e2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -29,7 +29,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { $seconds | Should -Be "1577836800" if ($isLinux) { - $seconds | Should -Be (date --date='01/01/2020 UTC' +%s) + $dateString = "01/01/2020 UTC" + if ( (Get-PlatformInfo) -eq "alpine" ) { + $dateString = "2020-01-01" + } + $expected = date --date=${dateString} +%s + $seconds | Should -Be $expected } } diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 3b3aa271ed2..6281d001c3d 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -7,6 +7,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } BeforeAll { + $IsAlpine = (Get-PlatformInfo) -eq "alpine" Import-Module PSDesiredStateConfiguration $dscModule = Get-Module PSDesiredStateConfiguration $baseSchemaPath = Join-Path $dscModule.ModuleBase 'Configuration' @@ -20,7 +21,7 @@ Describe "DSC MOF Compilation" -tags "CI" { $env:PSModulePath = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules } - It "Should be able to compile a MOF from a basic configuration" -Skip:($IsMacOS -or $IsWindows) { + It "Should be able to compile a MOF from a basic configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) { [Scriptblock]::Create(@" configuration DSCTestConfig { @@ -39,7 +40,7 @@ Describe "DSC MOF Compilation" -tags "CI" { "TestDrive:\DscTestConfig1\localhost.mof" | Should -Exist } - It "Should be able to compile a MOF from another basic configuration" -Skip:($IsMacOS -or $IsWindows) { + It "Should be able to compile a MOF from another basic configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) { [Scriptblock]::Create(@" configuration DSCTestConfig { @@ -61,7 +62,7 @@ Describe "DSC MOF Compilation" -tags "CI" { "TestDrive:\DscTestConfig2\localhost.mof" | Should -Exist } - It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows) { + It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) { [Scriptblock]::Create(@" Configuration WordPressServer{ @@ -170,7 +171,7 @@ Describe "DSC MOF Compilation" -tags "CI" { "TestDrive:\DscTestConfig3\CentOS.mof" | Should -Exist } - It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) { + It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux -or $IsAlpine) { [Scriptblock]::Create(@" configuration DSCTestConfig { @@ -190,7 +191,7 @@ Describe "DSC MOF Compilation" -tags "CI" { "TestDrive:\DscTestConfig4\localhost.mof" | Should -Exist } - It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) { + It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux -or $IsAlpine) { [Scriptblock]::Create(@" configuration DSCTestConfig { diff --git a/test/powershell/engine/Remoting/PSSession.Tests.ps1 b/test/powershell/engine/Remoting/PSSession.Tests.ps1 index 8221e405e95..892b843435d 100644 --- a/test/powershell/engine/Remoting/PSSession.Tests.ps1 +++ b/test/powershell/engine/Remoting/PSSession.Tests.ps1 @@ -73,6 +73,11 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS It "" -TestCases $testCases { param ($scriptBlock, $expectedErrorCode) + if ( (Get-PlatformInfo) -eq "alpine" ) { + Set-ItResult -Pending -Because "MI library not available for Alpine" + return + } + $er = { & $scriptBlock } | Should -Throw -ErrorId 'System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand' -PassThru $er.Exception.ErrorCode | Should -Be $expectedErrorCode } diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index 173ad0946b1..923e5f5a4cb 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -5,6 +5,11 @@ Import-Module HelpersCommon Describe "New-PSSession basic test" -Tag @("CI") { It "New-PSSession should not crash powershell" { + if ( (Get-PlatformInfo) -eq "alpine" ) { + Set-ItResult -Pending -Because "MI library not available for Alpine" + return + } + { New-PSSession -ComputerName nonexistcomputer -Authentication Basic } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.NewPSSessionCommand" } @@ -12,6 +17,11 @@ 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) { + if ( (Get-PlatformInfo) -eq "alpine" ) { + Set-ItResult -Pending -Because "MI library not available for Alpine" + return + } + $password = ConvertTo-SecureString -String "password" -AsPlainText -Force $credential = [PSCredential]::new('username', $password) @@ -23,6 +33,11 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { } It "New-PSSession should NOT throw a ConnectFailed exception when specifying Basic Auth over HTTPS on Unix" -skip:($IsWindows) { + if ( (Get-PlatformInfo) -eq "alpine" ) { + Set-ItResult -Pending -Because "MI library not available for Alpine" + return + } + $password = ConvertTo-SecureString -String "password" -AsPlainText -Force $credential = [PSCredential]::new('username', $password) diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 53f543559dd..42bd6548dfb 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -363,3 +363,21 @@ function New-ComplexPassword $password } + +# return a specific string with regard to platform information +function Get-PlatformInfo +{ + if ( $IsWindows ) { + return "windows" + } + if ( $IsMacOS ) { + return "macos" + } + if ( $IsLinux ) { + $osrelease = Get-Content /etc/os-release | ConvertFrom-StringData + if ( -not [string]::IsNullOrEmpty($osrelease.ID) ) { + return $osrelease.ID + } + return "unknown" + } +} From 234b352d80a4dc952547b76cc6cb59b13ed28224 Mon Sep 17 00:00:00 2001 From: James Truher Date: Wed, 21 Aug 2019 14:38:09 -0700 Subject: [PATCH 2/3] include changes for building alpine test tools during validation run --- build.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 9169d1cbdad..ba52d96f764 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1006,7 +1006,13 @@ function Start-PSPester { Write-Verbose "Running pester tests at '$path' with tag '$($Tag -join ''', ''')' and ExcludeTag '$($ExcludeTag -join ''', ''')'" -Verbose if(!$SkipTestToolBuild.IsPresent) { - Publish-PSTestTools | ForEach-Object {Write-Host $_} + $publishArgs = @{ } + # if we are building for Alpine, we must include the runtime as linux-x64 + # will not build runnable test tools + if ( $Environment.IsAlpine ) { + $publishArgs['runtime'] = 'alpine-x64' + } + Publish-PSTestTools @publishArgs | ForEach-Object {Write-Host $_} } # All concatenated commands/arguments are suffixed with the delimiter (space) From 9401f70520b33caafce7ad30ff4b3b4f3a2de916 Mon Sep 17 00:00:00 2001 From: James Truher Date: Wed, 21 Aug 2019 14:54:54 -0700 Subject: [PATCH 3/3] add Get-PlatformInfo function to export list --- test/tools/Modules/HelpersCommon/HelpersCommon.psd1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index a72a7795121..4e97a5f3734 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -34,6 +34,7 @@ FunctionsToExport = @( 'Test-TesthookIsSet' 'Wait-FileToBePresent' 'Wait-UntilTrue' + 'Get-PlatformInfo' ) CmdletsToExport= @()