84 tests in collectors/tests, run with Invoke-CollectorTests.ps1 (~15 s, PowerShell 7.2+ and Pester 5.5+): - Module.Tests: the shared module (property lookup, time format, config/lookback, sent-run state and pruning, dry runs, exit codes, 401 detection) - Veeam/Mars/Wsb/Vb365.Tests: each collector run in its own process against its mock and a stand-in ingest API, asserting the behaviours confirmed on real servers: VBR 13 live schedule, copy jobs, MARS UTC times and ErrorCode 0, WSB culture-formatted times and nested VMs, VB365 organization mapping, log prefixes and retries, state and resending, rejected keys - Installers.Tests: config, files and scheduled task from each installer, with stand-ins for icacls / Task Scheduler / the key prompt Collectors run under the test runner's PowerShell, or another shell via -CollectorShell (e.g. powershell.exe, to test under Windows PowerShell 5.1 like the MARS, WSB and VB365 servers). The mocks take their "now" from MOCK_NOW so expectations can't drift with the clock; the WSB mock gains -RunningJobFinished for the running-to-finished case. Each of 12 past bugs, put back one at a time, fails the test for its behaviour (and the runner exits 1). Co-Authored-By: Claude Opus 5.5 <[email protected]>
63 lines
2.4 KiB
PowerShell
63 lines
2.4 KiB
PowerShell
<#
|
|
.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 })
|