Skip to content

Commit

Permalink
Centralise the way we invoke pester tests (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-richardson authored Oct 28, 2021
1 parent b04a3c8 commit 2360776
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 66 deletions.
24 changes: 24 additions & 0 deletions Tests/powershell-helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ function Test-AppExists($appName) {
return $null -ne $command
}

function Invoke-PesterTests {
Write-Output "##teamcity[blockOpened name='Pester tests']"
Write-Output "##teamcity[blockOpened name='Importing modules']"
Write-Output "Importing Pester module"
Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1"
Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0"
Write-Output "##teamcity[blockClosed name='Importing modules']"
Write-Output "Running Pester Tests"
$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.PassThru = $true
$configuration.Run.Exit = $true
$configuration.Run.Path = @("./Tests", "./OctopusDSC")
$configuration.Output.Verbosity = 'Detailed'
$result = Invoke-Pester -configuration $configuration
write-output "##teamcity[publishArtifacts 'PesterTestResults.xml']"
if ($result.FailedCount -gt 0) {
exit 1
}
Write-Output "##teamcity[blockClosed name='Pester tests']"
}

function Import-PowerShellModule ($Name, $MinimumVersion) {
$command = Get-Module $Name -listavailable
if ($null -eq $command) {
Expand Down
19 changes: 1 addition & 18 deletions build-aws.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,7 @@ Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun

if(-not $SkipPester) {
Write-Output "##teamcity[blockOpened name='Pester tests']"
Write-Output "Importing Pester module"
Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1"
Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0"

Write-Output "Running Pester Tests"
$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.PassThru = $true
$configuration.Run.Exit = $true
$result = Invoke-Pester -configuration $configuration
write-output "##teamcity[publishArtifacts 'PesterTestResults.xml']"
if ($result.FailedCount -gt 0) {
exit 1
}
Write-Output "##teamcity[blockClosed name='Pester tests']"
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}
Expand Down
19 changes: 3 additions & 16 deletions build-azure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,9 @@ Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun

if(-not $SkipPester) {
Write-Output "Importing Pester module"
Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1"
Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0"

Write-Output "Running Pester Tests"
$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.PassThru = $true
$configuration.Run.Exit = $true
$configuration.Output.Verbosity = 'Detailed'
$result = Invoke-Pester -configuration $configuration
if ($result.FailedCount -gt 0) {
exit 1
}
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}

Write-Output "Running 'vagrant up --provider azure'"
Expand Down
17 changes: 1 addition & 16 deletions build-hyperv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,7 @@ Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun

if(-not $SkipPester) {
Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1"
Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0"
Write-Output "Running Pester Tests"

$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.PassThru = $true
$configuration.Run.Exit = $true
$configuration.Output.Verbosity = 'Detailed'
$result = Invoke-Pester -configuration $configuration

if ($result.FailedCount -gt 0) {
exit 1
}
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}
Expand Down
17 changes: 1 addition & 16 deletions build-virtualbox.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,7 @@ Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun

if(-not $SkipPester) {
Write-Output "Importing Pester module"
Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1"
Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0"

Write-Output "Running Pester Tests"
$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.PassThru = $true
$configuration.Run.Exit = $true
$configuration.Output.Verbosity = 'Detailed'
$result = Invoke-Pester -configuration $configuration
if ($result.FailedCount -gt 0) {
exit 1
}
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}
Expand Down

0 comments on commit 2360776

Please sign in to comment.