# Collector tests Pester tests for the collectors, the shared module and the installers. Each collector runs against its mock (`collectors//tests/Mock*.ps1`, built from real servers' diagnostic output) and a stand-in for the ingest API, so no backup product or dashboard is needed. ```powershell Install-Module Pester -MinimumVersion 5.5 -Scope CurrentUser # once ./collectors/tests/Invoke-CollectorTests.ps1 # everything, ~15 s ./collectors/tests/Invoke-CollectorTests.ps1 -Path ./collectors/tests/Wsb.Tests.ps1 ``` Needs PowerShell 7.2+ to run the tests. Collectors run in their own process, under the same PowerShell by default. On Windows, run them under Windows PowerShell 5.1, as the MARS, WSB and VB365 servers do: ```powershell ./collectors/tests/Invoke-CollectorTests.ps1 -CollectorShell powershell.exe ``` The runner exits non-zero if anything fails. ## What's covered | File | Checks | |---|---| | `Module.Tests.ps1` | `BackupDashboard.Collector.psm1`: property lookup, time format, config and lookback, state (recording sent runs, pruning), dry runs, exit codes, 401 detection | | `Veeam.Tests.ps1` | Next run from the live schedule (VBR 13), none for copy/disabled jobs; copy-job worker sessions; statuses and messages; state and resending; rejected key; missing config | | `Mars.Tests.ps1` | UTC job times; ErrorCode 0 isn't an error; failed files → warning; next run from the schedule; JobName; state | | `Wsb.Tests.ps1` | Culture-formatted times (en-US and en-GB); VMs nested in VirtualMachineList; HRESULTs; failure log only when relevant; running → finished merging on start time | | `Vb365.Tests.ps1` | Organization → company mapping; `[Warning]`/`[Failed]` log prefixes; retries; "187.2 MB" sizes; state | | `Installers.Tests.ps1` | Config written (incl. the VB365 map), files copied (collector + module), task registered (shell, interval, SYSTEM), refusals before changing anything | Each of these was a real bug or a real-server finding. To check the suite still catches them, put one back (e.g. read `$Job.ScheduleOptions.NextRun` instead of `GetScheduleOptions()` in the Veeam collector) and run the tests: they should fail. ## Adding a collector 1. Write `collectors//tests/Mock.ps1` from the product's diagnostic output, taking its time from `$env:MOCK_NOW` like the others. 2. Add `` to `Invoke-Collector`'s `ValidateSet` in `TestHelpers.psm1`. 3. Add `.Tests.ps1`, one `It` per behaviour confirmed on a real server.