Migrates to Pester5+ tests (#59)
Some checks reported errors
continuous-integration/drone/push Build was killed

#### 📖 Summary

- update Pester tests to Pester5+ compatiple layout
- switch to dotnet base imaged
  - dotnet binary required for publishung powershell modules (Publish-Module)

#### 📑 Test Plan

> 💡 Select your test plan for the code changes.

- [x] Tested via Drone.io pipeline
- [ ] Custom test
- [ ] No test plan

##### Details / Justification

<!-- Add your test details or justification for missing tests here. -->

#### 📚 Additional Notes

<!-- A place for additional detail notes. -->

Co-authored-by: OCram85 <marco.blessing@googlemail.com>
Reviewed-on: #59
This commit is contained in:
2022-07-14 13:37:12 +02:00
parent e3404666d4
commit d4b00a5308
31 changed files with 636 additions and 333 deletions

View File

@ -80,6 +80,35 @@ function Invoke-InstallDependencies {
}
}
function Start-PSScriptAnalyzer {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions',
'',
Justification = 'justification'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSProvideCommentHelp',
'',
Justification = 'internal function'
)]
param ()
process {
$AnalyzerSettings = @{
Path = './src/'
Recurse = $true
Settings = './tools/PSScriptAnalyzerSettings.psd1'
ReportSummary = $true
ErrorAction = 'Stop'
}
$AnalyzerResults = Invoke-ScriptAnalyzer @AnalyzerSettings
if ( $AnalyzerResults ) {
Write-Output -InputObject $AnalyzerResults
}
}
}
function Invoke-Linter {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
@ -90,16 +119,20 @@ function Invoke-Linter {
param ()
process {
Import-Module -Name PSScriptAnalyzer
$AnalyzerSettings = @{
Path = './src/'
Recurse = $true
Settings = './tools/PSScriptAnalyzerSettings.psd1'
ReportSummary = $true
ErrorAction = 'Stop'
}
try {
$AnalyzerResults = Invoke-ScriptAnalyzer @AnalyzerSettings
$AnalyzerResults = Start-PSScriptAnalyzer
}
catch {
Write-Debug -Message $_.Exception.Message -Debug
if ($_.Exception.Message -match 'Object reference not set') {
Write-Debug -Message 'ReRun PSScriptAnalyzer' -Debug
$AnalyzerResults = Start-PSScriptAnalyzer
}
else {
Write-Error -Message 'PSScriptAnalyzer failer'
}
}
finally {
if ( $AnalyzerResults ) {
$AnalyzerResults | Sort-Object -Property @(
"ScriptName",
@ -111,12 +144,10 @@ function Invoke-Linter {
"RuleName",
"Message"
) -AutoSize | Out-String | Write-Verbose -Verbose
Update-BuildStateFile
throw 'PS Script Analyzer failed!'
}
}
catch {
Write-Debug -Message $_.Exception.Message -Debug
Write-Error -Message 'PSScriptAnalyzer failer'
}
}
}
@ -171,8 +202,49 @@ function Invoke-UnitTest {
$PesterConf.Filter.ExcludeTag = $ExcludeTag
}
$TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop'
if ($TestResults.FailedCount -gt 0) {
Update-BuildStateFile
throw ('{0} tests failed!' -f $TestResults.FailedCount)
}
if ($PassThru.IsPresent) {
Write-Output -InputObject $TestResults
}
}
}
function Update-BuildStateFile {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$StepName = $Env:DRONE_FAILED_STEPS
)
process {
$StateFilePath = Join-Path -Path $PWD -ChildPath './STATE.xml'
if (Test-Path -Path $StateFilePath) {
$StateContent = Import-Clixml -Path $StateFilePath
$StateContent.Steps += $StepName
}
else {
$StateContent = [PSCustomObject]@{
Steps = @($StepName)
}
}
Export-Clixml -Path $StateFilePath -InputObject $StateContent -Force -Encoding utf8NoBOM
}
}
function Invoke-BuildState {
[CmdletBinding()]
param ()
process {
$StateFilePath = Join-Path -Path $PWD -ChildPath './STATE.xml'
if ( Test-Path -Path $StateFilePath ) {
throw 'One one more pipeline steps failed. Marking the pipeline as failed!'
}
}
}