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
}
It "Skip versions with 1 digin" {
It "Skip versions with 1 digit" {
$actualOutput = Format-Versions -Versions @("14", "v2")
$expectedOutput = @()
$actualOutput | Should -Be $expectedOutput
@ -37,27 +37,42 @@ Describe "Format-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")
It "Include filter" {
It "Include filter only" {
$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")
$actualOutput | Should -Be $expectedOutput
}
It "Exclude filter" {
It "Include and exclude filters" {
$includeFilters = @("10.*", "12.*")
$excludeFilters = @("10.0.*", "12.4.3")
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
$expectedOutput = @("10.5.6", "12.5.1")
$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" {
$distInput = @("14.2.0", "14.3.0", "14.4.0", "14.4.1")
$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")
$actualOutput | Should -Be $expectedOutput
}

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

@ -5,9 +5,7 @@ function Format-Versions {
[Version[]] $formattedVersions = @()
foreach($version in $Versions) {
$substredVersion = $null
foreach($version in $Versions) {
# 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)')) {
Write-Host "Invalid version format - $version"
@ -34,23 +32,22 @@ function Format-Versions {
function Filter-Versions {
param (
[Parameter(Mandatory)] [string[]] $Versions,
[Parameter(Mandatory)] [string] $VersionFilter,
[Parameter(Mandatory)] [bool] $IncludeVersions
[Parameter(Mandatory)] [version[]] $Versions,
[string[]] $IncludeFilters,
[string[]] $ExcludeFilters
)
$versionFilters = $VersionFilter.Split(',')
[Version[]] $filteredVersions = @()
foreach($filter in $versionFilters) {
if ($IncludeVersions) {
$filteredVersions += $Versions | Where-Object { $_ -like $filter }
} else {
$filteredVersions += $Versions | Where-Object { $_ -notlike $filter }
}
if ($IncludeFilters.Length -eq 0) {
$IncludeFilters = @('*')
}
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 {
@ -59,8 +56,5 @@ function Skip-ExistingVersions {
[Parameter(Mandatory)] [string[]] $VersionsFromDist
)
$newVersions = @()
$newVersions += $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ }
return $newVersions
return $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ }
}
Loading…
Cancel
Save