mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-30 00:47:07 +00:00
refactor: make all integration test files self-contained
Each test file now creates and cleans up its own resources: - 06_VMs: restores own AfterAll cleanup for pester-test-vm - 07_Snapshots: creates pester-snap-vm, tests snapshots, cleans up - 09_CloudInit: creates pester-ci-vm with cloud-init drive, cleans up - 15_Tasks: creates pester-task-vm, tests task CRUD, cleans up Removed cross-file dependency helpers (Find-TestVm, Register-TestResource) from _IntegrationHelper.ps1 — no longer needed. Each file can now run independently via -Tests filter. If a Setup context fails, subsequent tests in the same file skip gracefully. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -145,43 +145,3 @@ function script:Disconnect-TestPve {
|
||||
#>
|
||||
try { Disconnect-PveServer -ErrorAction SilentlyContinue } catch { }
|
||||
}
|
||||
|
||||
# ── Resource discovery helpers ───────────────────────────────────────────
|
||||
# These allow later test files to find resources created by earlier files
|
||||
# without sharing script-scoped variables. If the resource doesn't exist,
|
||||
# the caller gets $null and should skip.
|
||||
|
||||
function script:Find-TestVm {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Finds the pester-test-vm by checking env state or querying PVE.
|
||||
#>
|
||||
param([string]$Name = 'pester-test-vm')
|
||||
|
||||
# Check env var first (set by the file that created it)
|
||||
$envKey = "PVETEST_STATE_$($Name.Replace('-','_').ToUpper())"
|
||||
$vmId = [System.Environment]::GetEnvironmentVariable($envKey)
|
||||
if ($vmId) { return [int]$vmId }
|
||||
|
||||
# Fall back to querying PVE
|
||||
try {
|
||||
$vms = Get-PveVm -Node $script:Node -ErrorAction Stop
|
||||
$match = $vms | Where-Object { $_.Name -eq $Name } | Select-Object -First 1
|
||||
if ($match) { return [int]$match.VmId }
|
||||
} catch { }
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function script:Register-TestResource {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Registers a resource VMID in env for cross-file discovery.
|
||||
#>
|
||||
param(
|
||||
[string]$Name,
|
||||
[int]$VmId
|
||||
)
|
||||
$envKey = "PVETEST_STATE_$($Name.Replace('-','_').ToUpper())"
|
||||
[System.Environment]::SetEnvironmentVariable($envKey, $VmId.ToString())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user