Skip to content

Commit 3943f18

Browse files
JamesWTruherTravisEz13
authored andcommitted
Alpine validation changes (PowerShell#10428)
1 parent 8b9f412 commit 3943f18

File tree

9 files changed

+69
-8
lines changed

9 files changed

+69
-8
lines changed

build.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,13 @@ function Start-PSPester {
10061006
Write-Verbose "Running pester tests at '$path' with tag '$($Tag -join ''', ''')' and ExcludeTag '$($ExcludeTag -join ''', ''')'" -Verbose
10071007
if(!$SkipTestToolBuild.IsPresent)
10081008
{
1009-
Publish-PSTestTools | ForEach-Object {Write-Host $_}
1009+
$publishArgs = @{ }
1010+
# if we are building for Alpine, we must include the runtime as linux-x64
1011+
# will not build runnable test tools
1012+
if ( $Environment.IsAlpine ) {
1013+
$publishArgs['runtime'] = 'alpine-x64'
1014+
}
1015+
Publish-PSTestTools @publishArgs | ForEach-Object {Write-Host $_}
10101016
}
10111017

10121018
# All concatenated commands/arguments are suffixed with the delimiter (space)

test/powershell/Host/Startup.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ Describe "Validate start of console host" -Tag CI {
103103
}
104104

105105
It "No new assemblies are loaded" {
106+
if ( (Get-PlatformInfo) -eq "alpine" ) {
107+
Set-ItResult -Pending -Because "Missing MI library causes list to be different"
108+
return
109+
}
110+
106111
$diffs = Compare-Object -ReferenceObject $allowedAssemblies -DifferenceObject $loadedAssemblies
107112

108113
if ($null -ne $diffs) {

test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ Describe "Test-Connection" -tags "CI" {
108108
# After .Net Core fix we should have 'DontFragment | Should -Be $true' here.
109109
$result1.Replies[0].Options.Ttl | Should -BeLessOrEqual 128
110110
if (!$isWindows) {
111-
$result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty
111+
if ( (Get-PlatformInfo) -eq "alpine" ) {
112+
$result1.Replies[0].Options.DontFragment | Should -Be $true
113+
}
114+
else {
115+
$result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty
116+
}
112117
# depending on the network configuration any of the following should be returned
113118
$result2.Replies[0].Status | Should -BeIn "TtlExpired","TimedOut","Success"
114119
} else {

test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" {
2929

3030
$seconds | Should -Be "1577836800"
3131
if ($isLinux) {
32-
$seconds | Should -Be (date --date='01/01/2020 UTC' +%s)
32+
$dateString = "01/01/2020 UTC"
33+
if ( (Get-PlatformInfo) -eq "alpine" ) {
34+
$dateString = "2020-01-01"
35+
}
36+
$expected = date --date=${dateString} +%s
37+
$seconds | Should -Be $expected
3338
}
3439
}
3540

test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
77
}
88

99
BeforeAll {
10+
$IsAlpine = (Get-PlatformInfo) -eq "alpine"
1011
Import-Module PSDesiredStateConfiguration
1112
$dscModule = Get-Module PSDesiredStateConfiguration
1213
$baseSchemaPath = Join-Path $dscModule.ModuleBase 'Configuration'
@@ -20,7 +21,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
2021
$env:PSModulePath = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules
2122
}
2223

23-
It "Should be able to compile a MOF from a basic configuration" -Skip:($IsMacOS -or $IsWindows) {
24+
It "Should be able to compile a MOF from a basic configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) {
2425
[Scriptblock]::Create(@"
2526
configuration DSCTestConfig
2627
{
@@ -39,7 +40,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
3940
"TestDrive:\DscTestConfig1\localhost.mof" | Should -Exist
4041
}
4142

42-
It "Should be able to compile a MOF from another basic configuration" -Skip:($IsMacOS -or $IsWindows) {
43+
It "Should be able to compile a MOF from another basic configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) {
4344
[Scriptblock]::Create(@"
4445
configuration DSCTestConfig
4546
{
@@ -61,7 +62,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
6162
"TestDrive:\DscTestConfig2\localhost.mof" | Should -Exist
6263
}
6364

64-
It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows) {
65+
It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows -or $IsAlpine) {
6566
[Scriptblock]::Create(@"
6667
Configuration WordPressServer{
6768
@@ -170,7 +171,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
170171
"TestDrive:\DscTestConfig3\CentOS.mof" | Should -Exist
171172
}
172173

173-
It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) {
174+
It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux -or $IsAlpine) {
174175
[Scriptblock]::Create(@"
175176
configuration DSCTestConfig
176177
{
@@ -190,7 +191,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
190191
"TestDrive:\DscTestConfig4\localhost.mof" | Should -Exist
191192
}
192193

193-
It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) {
194+
It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux -or $IsAlpine) {
194195
[Scriptblock]::Create(@"
195196
configuration DSCTestConfig
196197
{

test/powershell/engine/Remoting/PSSession.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS
7373
It "<Name>" -TestCases $testCases {
7474
param ($scriptBlock, $expectedErrorCode)
7575

76+
if ( (Get-PlatformInfo) -eq "alpine" ) {
77+
Set-ItResult -Pending -Because "MI library not available for Alpine"
78+
return
79+
}
80+
7681
$er = { & $scriptBlock } | Should -Throw -ErrorId 'System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand' -PassThru
7782
$er.Exception.ErrorCode | Should -Be $expectedErrorCode
7883
}

test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ Import-Module HelpersCommon
55

66
Describe "New-PSSession basic test" -Tag @("CI") {
77
It "New-PSSession should not crash powershell" {
8+
if ( (Get-PlatformInfo) -eq "alpine" ) {
9+
Set-ItResult -Pending -Because "MI library not available for Alpine"
10+
return
11+
}
12+
813
{ New-PSSession -ComputerName nonexistcomputer -Authentication Basic } |
914
Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.NewPSSessionCommand"
1015
}
1116
}
1217

1318
Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") {
1419
It "New-PSSession should throw when specifying Basic Auth over HTTP on Unix" -skip:($IsWindows) {
20+
if ( (Get-PlatformInfo) -eq "alpine" ) {
21+
Set-ItResult -Pending -Because "MI library not available for Alpine"
22+
return
23+
}
24+
1525
$password = ConvertTo-SecureString -String "password" -AsPlainText -Force
1626
$credential = [PSCredential]::new('username', $password)
1727

@@ -23,6 +33,11 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") {
2333
}
2434

2535
It "New-PSSession should NOT throw a ConnectFailed exception when specifying Basic Auth over HTTPS on Unix" -skip:($IsWindows) {
36+
if ( (Get-PlatformInfo) -eq "alpine" ) {
37+
Set-ItResult -Pending -Because "MI library not available for Alpine"
38+
return
39+
}
40+
2641
$password = ConvertTo-SecureString -String "password" -AsPlainText -Force
2742
$credential = [PSCredential]::new('username', $password)
2843

test/tools/Modules/HelpersCommon/HelpersCommon.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ FunctionsToExport = @(
3434
'Test-TesthookIsSet'
3535
'Wait-FileToBePresent'
3636
'Wait-UntilTrue'
37+
'Get-PlatformInfo'
3738
)
3839

3940
CmdletsToExport= @()

test/tools/Modules/HelpersCommon/HelpersCommon.psm1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,21 @@ function New-ComplexPassword
363363

364364
$password
365365
}
366+
367+
# return a specific string with regard to platform information
368+
function Get-PlatformInfo
369+
{
370+
if ( $IsWindows ) {
371+
return "windows"
372+
}
373+
if ( $IsMacOS ) {
374+
return "macos"
375+
}
376+
if ( $IsLinux ) {
377+
$osrelease = Get-Content /etc/os-release | ConvertFrom-StringData
378+
if ( -not [string]::IsNullOrEmpty($osrelease.ID) ) {
379+
return $osrelease.ID
380+
}
381+
return "unknown"
382+
}
383+
}

0 commit comments

Comments
 (0)