Update Get-PlatformInfo helper and tests for Debian 10, 11 and CentOS 8 (#11842)

This commit is contained in:
Aditya Patwardhan 2020-02-12 18:35:24 -08:00 committed by GitHub
parent cec9deb72a
commit a578347b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 16 deletions

View file

@ -103,7 +103,7 @@ Describe "Validate start of console host" -Tag CI {
}
It "No new assemblies are loaded" {
if ( (Get-PlatformInfo) -eq "alpine" ) {
if ( (Get-PlatformInfo).Platform -eq "alpine" ) {
Set-ItResult -Pending -Because "Missing MI library causes list to be different"
return
}

View file

@ -64,7 +64,7 @@ Describe "Test-Connection" -tags "CI" {
{ $result = Test-Connection "fakeHost" -Count 1 -Quiet -ErrorAction Stop } |
Should -Throw -ErrorId "TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand"
# Error code = 11001 - Host not found.
if ((Get-PlatformInfo) -match "raspbian") {
if ((Get-PlatformInfo).Platform -match "raspbian") {
$code = 11
}
elseif (!$IsWindows) {

View file

@ -35,7 +35,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" {
$seconds | Should -Be "1577836800"
if ($IsLinux) {
$dateString = "01/01/2020 UTC"
if ( (Get-PlatformInfo) -eq "alpine" ) {
if ( (Get-PlatformInfo).Platform -eq "alpine" ) {
$dateString = "2020-01-01"
}
$expected = date --date=${dateString} +%s

View file

@ -7,7 +7,12 @@ Describe "DSC MOF Compilation" -tags "CI" {
}
BeforeAll {
$SkipAdditionalPlatforms = (Get-PlatformInfo) -match "alpine|raspbian"
$platformInfo = Get-PlatformInfo
$SkipAdditionalPlatforms =
($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')
Import-Module PSDesiredStateConfiguration
$dscModule = Get-Module PSDesiredStateConfiguration
$baseSchemaPath = Join-Path $dscModule.ModuleBase 'Configuration'

View file

@ -28,7 +28,12 @@ Function Test-IsInvokeDscResourceEnable {
Describe "Test PSDesiredStateConfiguration" -tags CI {
BeforeAll {
$MissingLibmi = $false
if ((Get-PlatformInfo) -match "alpine|raspbian") {
$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')
) {
$MissingLibmi = $true
}
}

View file

@ -74,8 +74,12 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS
param ($scriptBlock, $expectedErrorCode)
$platformInfo = Get-PlatformInfo
if (($platformInfo -eq "alpine") -or ($platformInfo -eq "raspbian")) {
Set-ItResult -Skipped -Because "MI library not available for Alpine or Raspberry Pi"
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')
) {
Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8"
return
}

View file

@ -6,8 +6,12 @@ Import-Module HelpersCommon
Describe "New-PSSession basic test" -Tag @("CI") {
It "New-PSSession should not crash powershell" {
$platformInfo = Get-PlatformInfo
if (($platformInfo -eq "alpine") -or ($platformInfo -eq "raspbian")) {
Set-ItResult -Skipped -Because "MI library not available for Alpine or Raspberry Pi"
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')
) {
Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8"
return
}
@ -19,8 +23,12 @@ 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 -eq "alpine") -or ($platformInfo -eq "raspbian")) {
Set-ItResult -Skipped -Because "MI library not available for Alpine or Raspberry Pi"
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')
) {
Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8"
return
}

View file

@ -365,18 +365,26 @@ function New-ComplexPassword
}
# return a specific string with regard to platform information
function Get-PlatformInfo
{
function Get-PlatformInfo {
if ( $IsWindows ) {
return "windows"
return @{Platform = "windows"; Version = '' }
}
if ( $IsMacOS ) {
return "macos"
return @{Platform = "macos"; Version = '' }
}
if ( $IsLinux ) {
$osrelease = Get-Content /etc/os-release | ConvertFrom-StringData
if ( -not [string]::IsNullOrEmpty($osrelease.ID) ) {
return $osrelease.ID
$versionId = if (-not $osrelease.Version_ID ) {
''
} else {
$osrelease.Version_ID.trim('"')
}
$platform = $osrelease.ID.trim('"')
return @{Platform = $platform; Version = $versionId }
}
return "unknown"
}