From 38256635b9b368c074e9afaaa8aa22d048f12448 Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Sat, 11 May 2024 19:07:10 +0000 Subject: [PATCH] Test (integration): Utilize Pester for integration tests --- .../PSRepositoryReleaseManager.Tests.ps1 | 26 +++++++++ test/PSRepositoryReleaseManager.Tests.ps1 | 58 ------------------- test/test.ps1 | 7 ++- 3 files changed, 30 insertions(+), 61 deletions(-) create mode 100644 src/PSRepositoryReleaseManager/PSRepositoryReleaseManager.Tests.ps1 delete mode 100644 test/PSRepositoryReleaseManager.Tests.ps1 diff --git a/src/PSRepositoryReleaseManager/PSRepositoryReleaseManager.Tests.ps1 b/src/PSRepositoryReleaseManager/PSRepositoryReleaseManager.Tests.ps1 new file mode 100644 index 0000000..63f516e --- /dev/null +++ b/src/PSRepositoryReleaseManager/PSRepositoryReleaseManager.Tests.ps1 @@ -0,0 +1,26 @@ +Describe "PSRepositoryReleaseManager" -Tag 'Integration' { + BeforeAll { + $ErrorActionPreference = 'Continue' + $ErrorView = 'NormalView' + $VerbosePreference = 'Continue' + $env:RELEASE_TAG_REF = git describe --tags --abbrev=0 + } + BeforeEach { + } + AfterEach { + } + It "Runs Invoke-Generate.ps1 -ReleaseTagRef -ReleaseNotesVariant -ReleaseNotesPath" { + $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)/.release-notes.$variant.md" + + $stdout = ../src/scripts/ci/Invoke-Generate.ps1 -ReleaseTagRef $env:RELEASE_TAG_REF -ReleaseNotesVariant $env:RELEASE_NOTES_VARIANT -ReleaseNotesPath $env:RELEASE_NOTES_PATH + "Generate notes content:" | Write-Verbose + Get-Content -Path "$stdout" | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Host + } + } +} diff --git a/test/PSRepositoryReleaseManager.Tests.ps1 b/test/PSRepositoryReleaseManager.Tests.ps1 deleted file mode 100644 index 1c7a321..0000000 --- a/test/PSRepositoryReleaseManager.Tests.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -[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=@{ - ReleaseTagRef = $env:RELEASE_TAG_REF - ReleaseNotesVariant = $env:RELEASE_NOTES_VARIANT - ReleaseNotesPath = $env:RELEASE_NOTES_PATH - } - $iterations = 1 - & $functionTestScriptBlock -} - -########### -# Results # -########### -if ($failedCount -gt 0) { - "$failedCount tests failed." | Write-Warning -} -$failedCount diff --git a/test/test.ps1 b/test/test.ps1 index fc4fd37..7841407 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -15,7 +15,7 @@ try { # Run unit tests "Running unit tests" | Write-Verbose $testFailed = $false - $unitResult = Invoke-Pester -Script "$PSScriptRoot\..\src\PSRepositoryReleaseManager" -PassThru + $unitResult = Invoke-Pester -Script "$PSScriptRoot\..\src\PSRepositoryReleaseManager" -Tag 'Unit' -PassThru if ($unitResult.FailedCount -gt 0) { "$($unitResult.FailedCount) tests failed." | Write-Warning $testFailed = $true @@ -23,8 +23,9 @@ try { # Run integration tests "Running integration tests" | Write-Verbose - $integratedFailedCount = & "$PSScriptRoot\PSRepositoryReleaseManager.Tests.ps1" - if ($integratedFailedCount -gt 0) { + $integratedResult = Invoke-Pester -Script "$PSScriptRoot\..\src\PSRepositoryReleaseManager" -Tag 'Integration' -PassThru + if ($integratedResult.FailedCount -gt 0) { + "$($integratedResult.FailedCount) tests failed." | Write-Warning $testFailed = $true }