From 878c283d3b631405976a7b2d66d97951b5016cc9 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 16 Jun 2021 05:46:31 +0000 Subject: [PATCH] implement pester tests --- node-manifest-config.json | 8 --- packages-generation/manifest-utils.Tests.ps1 | 52 +++++++++++++++++++- 2 files changed, 51 insertions(+), 9 deletions(-) delete mode 100644 node-manifest-config.json diff --git a/node-manifest-config.json b/node-manifest-config.json deleted file mode 100644 index 5562000..0000000 --- a/node-manifest-config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "regex": "node-\\d+\\.\\d+\\.\\d+-(\\w+)-(x\\d+)", - "groups": { - "arch": 2, - "platform": 1 - }, - "lts_rule_expression": "(Invoke-RestMethod 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json').PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @{ Name = $_.Name.TrimStart('v'); Value = $_.Value.codename } }" -} \ No newline at end of file diff --git a/packages-generation/manifest-utils.Tests.ps1 b/packages-generation/manifest-utils.Tests.ps1 index 0fcaf05..15765d1 100644 --- a/packages-generation/manifest-utils.Tests.ps1 +++ b/packages-generation/manifest-utils.Tests.ps1 @@ -126,7 +126,7 @@ Describe "Build-VersionsManifest" { [PSCustomObject]@{ version = "3.8.3"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles } ) [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration - Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest + Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest } It "take latest published release for each version" { @@ -161,4 +161,54 @@ Describe "Build-VersionsManifest" { [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest } + + It "set correct lts value for versions" { + $releases = @( + @{ name = "14.2.1"; draft = false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-14T09:54:06Z"; assets = $assets }, + @{ name = "12.0.1"; draft = $false; prerelease = false; html_url = "fake_html_url"; published_at = "2020-05-06T11:45:36Z"; assets = $assets }, + @{ name = "16.2.2"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + ) + $configuration = @{ + regex = "python-\d+\.\d+\.\d+-(\w+)-([\w\.]+)?-?(x\d+)"; + groups = [PSCustomObject]@{ platform = 1; platform_version = 2; arch = "x64"; } + lts_rule_expression = "@(@{ Name = '14'; Value = 'Fermium' }, @{ Name = '12'; Value = 'Erbium' })" + } + $expectedManifest = @( + [PSCustomObject]@{ version = "16.2.2"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "14.2.1"; stable = $true; lts = "Fermium"; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "12.0.1"; stable = $true; lts = "Erbium"; release_url = "fake_html_url"; files = $expectedManifestFiles } + ) + [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration + Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest + } +} + +Describe "Get-VersionLtsStatus" { + $ltsRules = @( + @{ Name = "14"; Value = "Fermium" }, + @{ Name = "12"; Value = "Erbium" }, + @{ Name = "10"; Value = $true }, + @{ Name = "8.3"; Value = "LTS 8.3" } + ) + + It "lts label is matched" { + Get-VersionLtsStatus -Version "14.2.2" -LtsRules $ltsRules | Should -Be "Fermium" + Get-VersionLtsStatus -Version "12.3.1" -LtsRules $ltsRules | Should -Be "Erbium" + Get-VersionLtsStatus -Version "10.8.1" -LtsRules $ltsRules | Should -Be $true + Get-VersionLtsStatus -Version "8.3.2" -LtsRules $ltsRules | Should -Be "LTS 8.3" + Get-VersionLtsStatus -Version "14" -LtsRules $ltsRules | Should -Be "Fermium" + } + + It "lts label is not matched" { + Get-VersionLtsStatus -Version "9.1" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "13.8" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "5" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "8.4" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "142.5.1" -LtsRules $ltsRules | Should -Be $null + } + + It "no rules" { + Get-VersionLtsStatus -Version "14.2.2" | Should -Be $null + Get-VersionLtsStatus -Version "12.3.1" -LtsRules $null | Should -Be $null + } } \ No newline at end of file