<# .SYNOPSIS Runs the collector test suite (Pester): the shared module, each collector against its mock, and the installers. .DESCRIPTION Needs PowerShell 7.2+ and Pester 5.5+: Install-Module Pester -MinimumVersion 5.5 -Scope CurrentUser Each collector runs in its own process, by default under the same PowerShell running the tests. On Windows, use -CollectorShell to run them under Windows PowerShell 5.1 instead, as the MARS, WSB and VB365 servers do. Exits non-zero if any test fails, so it can gate a commit or CI job. .EXAMPLE ./collectors/tests/Invoke-CollectorTests.ps1 .EXAMPLE ./collectors/tests/Invoke-CollectorTests.ps1 -CollectorShell powershell.exe .EXAMPLE ./collectors/tests/Invoke-CollectorTests.ps1 -Path ./collectors/tests/Wsb.Tests.ps1 #> #Requires -Version 7.2 [CmdletBinding()] param( # powershell.exe / pwsh / a full path: the shell the collectors and installers run under [string]$CollectorShell, # Test files or folders to run; defaults to every *.Tests.ps1 here [string[]]$Path = @($PSScriptRoot), [ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')][string]$Output = 'Detailed' ) $ErrorActionPreference = 'Stop' $pester = Get-Module -ListAvailable -Name Pester | Where-Object Version -GE '5.5' | Sort-Object Version -Descending | Select-Object -First 1 if (-not $pester) { throw 'Pester 5.5 or newer is needed: Install-Module Pester -MinimumVersion 5.5 -Scope CurrentUser' } Import-Module $pester if ($CollectorShell) { $resolved = Get-Command $CollectorShell -ErrorAction SilentlyContinue if (-not $resolved) { throw "Shell not found: $CollectorShell" } $env:COLLECTOR_TEST_SHELL = $resolved.Source } $shellName = if ($env:COLLECTOR_TEST_SHELL) { $env:COLLECTOR_TEST_SHELL } else { "this PowerShell ($($PSVersionTable.PSVersion))" } Write-Host "Collectors run under: $shellName" # All temp folders for this run, removed at the end $env:COLLECTOR_TEST_TEMP = Join-Path ([IO.Path]::GetTempPath()) ("backup-dashboard-tests-" + [guid]::NewGuid().ToString('N').Substring(0, 8)) try { $config = New-PesterConfiguration $config.Run.Path = $Path $config.Run.PassThru = $true $config.Output.Verbosity = $Output $result = Invoke-Pester -Configuration $config } finally { Remove-Item -Recurse -Force $env:COLLECTOR_TEST_TEMP -ErrorAction SilentlyContinue Remove-Item env:COLLECTOR_TEST_TEMP } exit $(if ($result.Result -eq 'Passed') { 0 } else { 1 })