Skip to content

Commit

Permalink
Merge pull request #16 from theohbrothers/test/integration-add-tests-…
Browse files Browse the repository at this point in the history
…for-src-scripts-ci-invoke-generate.ps1

Test (integration): Add tests for `src/scripts/ci/Invoke-Generate.ps1`
  • Loading branch information
joeltimothyoh authored Apr 26, 2024
2 parents ef27967 + 812899e commit 11fb024
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/PSRepositoryReleaseManager.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions test/test.ps1
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 11fb024

Please sign in to comment.