mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-31 17:28:06 +00:00
12874d168d
Split the 1544-line Integration.Tests.ps1 into 18 focused test files with numeric prefixes for execution ordering. New shared helper (_IntegrationHelper.ps1): - Credential-based auth (root@pam) instead of API tokens - Skip helpers for env var checks - Resource discovery (Find-TestVm) for cross-file dependencies - Register-TestResource for env-var state passing between files Files created: 00_Connection, 01_Nodes, 02_Users, 03_Storage, 03a_SharedStorage, 04_Network, 05_SDN, 06_VMs, 07_Snapshots, 08_Templates, 09_CloudInit, 10_Containers, 11_LinuxVM, 12_OVA, 13_Firewall, 14_Backup, 15_Tasks, 99_Cleanup Key changes: - All tests use root@pam credentials (not API tokens) - Each file self-contained with own BeforeAll/AfterAll cleanup - Token CRUD tests now idempotent (remove-before-create) - 99_Cleanup is safety-net for any leftover pester-* resources - SharedStorage renamed to 03a_SharedStorage Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
74 lines
2.3 KiB
PowerShell
74 lines
2.3 KiB
PowerShell
#Requires -Module Pester
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/_IntegrationHelper.ps1
|
|
Connect-TestPve
|
|
|
|
# Find the test VM created by 06_VMs.Tests.ps1
|
|
$script:TestVmId = Find-TestVm
|
|
|
|
function script:Skip-IfNoTestVm {
|
|
if (Skip-IfNoTarget) { return $true }
|
|
if ($null -eq $script:TestVmId) {
|
|
Set-ItResult -Skipped -Because 'No test VM found (pester-test-vm must exist from 06_VMs)'
|
|
return $true
|
|
}
|
|
return $false
|
|
}
|
|
}
|
|
|
|
AfterAll {
|
|
# Snapshot cleanup is inline (remove within the test).
|
|
# No VM cleanup here — 06_VMs owns pester-test-vm.
|
|
Disconnect-TestPve
|
|
}
|
|
|
|
Describe 'Snapshots — Integration' -Tag 'Integration' {
|
|
Context 'Snapshots' {
|
|
It 'Should create, list, and remove a snapshot' {
|
|
if (Skip-IfNoTestVm) { return }
|
|
|
|
# Ensure the VM is stopped for snapshot
|
|
$vm = Get-PveVm -Node $script:Node | Where-Object { $_.VmId -eq $script:TestVmId }
|
|
if ($vm.Status -eq 'running') {
|
|
Stop-PveVm -Node $script:Node -VmId $script:TestVmId -Wait -Timeout 30 -Confirm:$false | Out-Null
|
|
}
|
|
|
|
$snapName = 'pester-snap'
|
|
|
|
# Create
|
|
$createTask = New-PveSnapshot `
|
|
-Node $script:Node `
|
|
-VmId $script:TestVmId `
|
|
-Name $snapName `
|
|
-Description 'Created by Pester integration test' `
|
|
-Wait
|
|
|
|
$createTask | Should -Not -BeNullOrEmpty
|
|
|
|
# List and verify
|
|
$snapshots = Get-PveSnapshot -Node $script:Node -VmId $script:TestVmId
|
|
$snap = $snapshots | Where-Object { $_.Name -eq $snapName }
|
|
$snap | Should -Not -BeNullOrEmpty
|
|
|
|
# Restore
|
|
{ Restore-PveSnapshot `
|
|
-Node $script:Node `
|
|
-VmId $script:TestVmId `
|
|
-Name $snapName `
|
|
-Confirm:$false `
|
|
-Wait } | Should -Not -Throw
|
|
|
|
# Remove
|
|
$removeTask = Remove-PveSnapshot `
|
|
-Node $script:Node `
|
|
-VmId $script:TestVmId `
|
|
-Name $snapName `
|
|
-Confirm:$false `
|
|
-Wait
|
|
|
|
$removeTask | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|