From 812899ebd92f536a7bc39e1fa65500cffa57db1a Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Fri, 26 Apr 2024 00:10:59 +0000 Subject: [PATCH] Test (integration): Add tests for `src/scripts/ci/Invoke-Generate.ps1` --- test/PSRepositoryReleaseManager.Tests.ps1 | 54 +++++++++++++++++++++++ test/test.ps1 | 42 ++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/PSRepositoryReleaseManager.Tests.ps1 create mode 100644 test/test.ps1 diff --git a/test/PSRepositoryReleaseManager.Tests.ps1 b/test/PSRepositoryReleaseManager.Tests.ps1 new file mode 100644 index 0000000..328b33a --- /dev/null +++ b/test/PSRepositoryReleaseManager.Tests.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Continue' +$VerbosePreference = 'Continue' + +$failedCount = 0 + +$functionTestScriptBlock = { + try { + "Command: $script:cmd" | Write-Verbose + "Args:" | Write-Verbose + $script:cmdArgs | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose + for ($i=0; $i -le $script:iterations-1; $i++) { + "Iteration: $($i+1)" | Write-Verbose + if ($script:cmdArgs) { + $stdout = & $script:cmd @script:cmdArgs + }else { + $stdout = & $script:cmd + } + "Generate notes content:" | Write-Verbose + Get-Content -Path "$stdout" | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Host + } + }catch { + $_ | Write-Error + $script:failedCount++ + } +} + +# Globals +$env:RELEASE_TAG_REF = git describe --tags --abbrev=0 + +# Script: ci/Invoke-Generate.ps1 +$ReleaseNotesVariant = Get-ChildItem "../src/PSRepositoryReleaseManager/generate/variants" | % { $_.BaseName } +"Release Notes Variants:" | Write-Verbose +$ReleaseNotesVariant | Write-Host + +foreach ($variant in $ReleaseNotesVariant) { + $env:RELEASE_NOTES_VARIANT = $variant + $env:RELEASE_NOTES_PATH = "$(git rev-parse --show-toplevel)/test/.release-notes.$variant.md" + + $cmd = "../src/scripts/ci/Invoke-Generate.ps1" + $cmdArgs=@{} + $iterations = 1 + & $functionTestScriptBlock +} + +########### +# Results # +########### +if ($failedCount -gt 0) { + "$failedCount tests failed." | Write-Warning +} +$failedCount diff --git a/test/test.ps1 b/test/test.ps1 new file mode 100644 index 0000000..44c7817 --- /dev/null +++ b/test/test.ps1 @@ -0,0 +1,42 @@ +[CmdletBinding()] +param() + +Set-StrictMode -Version Latest +$VerbosePreference = 'Continue' +$global:PesterDebugPreference_ShowFullErrors = $true + +try { + Push-Location $PSScriptRoot + + # Install test dependencies + # "Installing test dependencies" | Write-Verbose + # & "$PSScriptRoot\scripts\dep\Install-TestDependencies.ps1" > $null + + # Run unit tests + "Running unit tests" | Write-Verbose + $testFailed = $false + $unitResult = Invoke-Pester -Script "$PSScriptRoot\..\src\PSRepositoryReleaseManager" -PassThru + if ($unitResult.FailedCount -gt 0) { + "$($unitResult.FailedCount) tests failed." | Write-Warning + $testFailed = $true + } + + # Run integration tests + "Running integration tests" | Write-Verbose + $integratedFailedCount = & "$PSScriptRoot\PSRepositoryReleaseManager.Tests.ps1" + if ($integratedFailedCount -gt 0) { + $testFailed = $true + } + + "Listing test artifacts" | Write-Verbose + git ls-files --others --exclude-standard + + "End of tests" | Write-Verbose + if ($testFailed) { + throw "One or more tests failed." + } +}catch { + throw +}finally { + Pop-Location +}