Add test cases and fix Filter-Versions function

pull/5/head
MaksimZhukov 5 years ago
parent e09bde7dec
commit 594c0c8899

@ -27,7 +27,7 @@ Describe "Format-Versions" {
$actualOutput | Should -Be $expectedOutput $actualOutput | Should -Be $expectedOutput
} }
It "Skip versions with 1 digin" { It "Skip versions with 1 digit" {
$actualOutput = Format-Versions -Versions @("14", "v2") $actualOutput = Format-Versions -Versions @("14", "v2")
$expectedOutput = @() $expectedOutput = @()
$actualOutput | Should -Be $expectedOutput $actualOutput | Should -Be $expectedOutput
@ -37,27 +37,42 @@ Describe "Format-Versions" {
Describe "Filter-Versions" { Describe "Filter-Versions" {
$inputVersions = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0") $inputVersions = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
It "Include filter" { It "Include filter only" {
$includeFilters = @("8.*", "14.*") $includeFilters = @("8.*", "14.*")
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters $excludeFilters = @()
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
$expectedOutput = @("8.2.1", "14.2.0") $expectedOutput = @("8.2.1", "14.2.0")
$actualOutput | Should -Be $expectedOutput $actualOutput | Should -Be $expectedOutput
} }
It "Exclude filter" { It "Include and exclude filters" {
$includeFilters = @("10.*", "12.*") $includeFilters = @("10.*", "12.*")
$excludeFilters = @("10.0.*", "12.4.3") $excludeFilters = @("10.0.*", "12.4.3")
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters $actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
$expectedOutput = @("10.5.6", "12.5.1") $expectedOutput = @("10.5.6", "12.5.1")
$actualOutput | Should -Be $expectedOutput $actualOutput | Should -Be $expectedOutput
} }
It "Exclude filter only" {
$includeFilters = @()
$excludeFilters = @("10.*", "12.*")
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
$expectedOutput = @("8.2.1", "9.3.3", "14.2.0")
$actualOutput | Should -Be $expectedOutput
}
It "Include and exclude filters are empty" {
$actualOutput = Filter-Versions -Versions $inputVersions
$expectedOutput = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
$actualOutput | Should -Be $expectedOutput
}
} }
Describe "Get-VersionsToBuild" { Describe "Skip-ExistingVersions" {
It "Substract versions correctly" { It "Substract versions correctly" {
$distInput = @("14.2.0", "14.3.0", "14.4.0", "14.4.1") $distInput = @("14.2.0", "14.3.0", "14.4.0", "14.4.1")
$manifestInput = @("12.0.0", "14.2.0", "14.4.0") $manifestInput = @("12.0.0", "14.2.0", "14.4.0")
$actualOutput = Get-VersionsToBuild -VersionsFromDist $distInput -VersionsFromManifest $manifestInput $actualOutput = Skip-ExistingVersions -VersionsFromDist $distInput -VersionsFromManifest $manifestInput
$expectedOutput = @("14.3.0", "14.4.1") $expectedOutput = @("14.3.0", "14.4.1")
$actualOutput | Should -Be $expectedOutput $actualOutput | Should -Be $expectedOutput
} }

@ -6,8 +6,8 @@ Check and return list of new available tool versions
param ( param (
[Parameter(Mandatory)] [string] $DistURL, [Parameter(Mandatory)] [string] $DistURL,
[Parameter(Mandatory)] [string] $ManifestLink, [Parameter(Mandatory)] [string] $ManifestLink,
[string] $VersionFilterToInclude, [string[]] $VersionFilterToInclude,
[string] $VersionFilterToExclude, [string[]] $VersionFilterToExclude,
[UInt32] $RetryIntervalSec = 60, [UInt32] $RetryIntervalSec = 60,
[UInt32] $RetryCount = 3 [UInt32] $RetryCount = 3
) )
@ -37,17 +37,9 @@ Write-Host "Get the packages list from $ManifestLink"
[Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist [Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist
if ($VersionFilterToInclude) { $formattedVersions = Filter-Versions -Versions $formattedVersions `
$formattedVersions = Filter-Versions -Versions $formattedVersions ` -IncludeFilters $VersionFilterToInclude `
-VersionFilter $VersionFilterToInclude ` -ExcludeFilters $VersionFilterToExclude
-IncludeVersions $true
}
if ($VersionFilterToExclude) {
$formattedVersions = Filter-Versions -Versions $formattedVersions `
-VersionFilter $VersionFilterToExclude `
-IncludeVersions $false
}
$versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest ` $versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest `
-VersionsFromDist $formattedVersions -VersionsFromDist $formattedVersions

@ -5,9 +5,7 @@ function Format-Versions {
[Version[]] $formattedVersions = @() [Version[]] $formattedVersions = @()
foreach($version in $Versions) { foreach($version in $Versions) {
$substredVersion = $null
# Cut a string from index of first digit because initially it has invalid format (v14.4.0 or go1.14.4) # Cut a string from index of first digit because initially it has invalid format (v14.4.0 or go1.14.4)
if (-not ($version -match '(?<number>\d)')) { if (-not ($version -match '(?<number>\d)')) {
Write-Host "Invalid version format - $version" Write-Host "Invalid version format - $version"
@ -34,23 +32,22 @@ function Format-Versions {
function Filter-Versions { function Filter-Versions {
param ( param (
[Parameter(Mandatory)] [string[]] $Versions, [Parameter(Mandatory)] [version[]] $Versions,
[Parameter(Mandatory)] [string] $VersionFilter, [string[]] $IncludeFilters,
[Parameter(Mandatory)] [bool] $IncludeVersions [string[]] $ExcludeFilters
) )
$versionFilters = $VersionFilter.Split(',') if ($IncludeFilters.Length -eq 0) {
[Version[]] $filteredVersions = @() $IncludeFilters = @('*')
foreach($filter in $versionFilters) {
if ($IncludeVersions) {
$filteredVersions += $Versions | Where-Object { $_ -like $filter }
} else {
$filteredVersions += $Versions | Where-Object { $_ -notlike $filter }
}
} }
return $filteredVersions return $Versions | Where-Object {
$ver = $_
$matchedIncludeFilters = $IncludeFilters | Where-Object { $ver -like $_ }
$matchedExcludeFilters = $ExcludeFilters | Where-Object { $ver -like $_ }
return ($matchedIncludeFilters -ne $null) -and ($matchedExcludeFilters -eq $null)
}
} }
function Skip-ExistingVersions { function Skip-ExistingVersions {
@ -59,8 +56,5 @@ function Skip-ExistingVersions {
[Parameter(Mandatory)] [string[]] $VersionsFromDist [Parameter(Mandatory)] [string[]] $VersionsFromDist
) )
$newVersions = @() return $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ }
$newVersions += $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ }
return $newVersions
} }
Loading…
Cancel
Save