mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-09 22:09:24 +00:00
117b10d222
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>
86 lines
2.6 KiB
PowerShell
86 lines
2.6 KiB
PowerShell
#Requires -Module Pester
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/_IntegrationHelper.ps1
|
|
Connect-TestPve
|
|
|
|
$script:CiVmId = $null
|
|
|
|
function script:Skip-IfNoCiVm {
|
|
if (Skip-IfNoTarget) { return $true }
|
|
if ($null -eq $script:CiVmId) {
|
|
Set-ItResult -Skipped -Because 'Cloud-init test VM was not created'
|
|
return $true
|
|
}
|
|
return $false
|
|
}
|
|
}
|
|
|
|
AfterAll {
|
|
if (-not $script:SkipReason -and $script:CiVmId) {
|
|
try {
|
|
Stop-PveVm -Node $script:Node -VmId $script:CiVmId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
|
|
} catch { }
|
|
Start-Sleep -Seconds 2
|
|
try {
|
|
Remove-PveVm -Node $script:Node -VmId $script:CiVmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue
|
|
} catch { }
|
|
}
|
|
Disconnect-TestPve
|
|
}
|
|
|
|
Describe 'Cloud-Init — Integration' -Tag 'Integration' {
|
|
|
|
Context 'Setup' {
|
|
It 'Should create a VM with cloud-init drive' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
$task = New-PveVm `
|
|
-Node $script:Node `
|
|
-Name 'pester-ci-vm' `
|
|
-Memory 128 `
|
|
-Cores 1 `
|
|
-Wait
|
|
|
|
$task | Should -Not -BeNullOrEmpty
|
|
|
|
$vm = Get-PveVm -Node $script:Node -Name 'pester-ci-vm' |
|
|
Select-Object -First 1
|
|
$vm | Should -Not -BeNullOrEmpty
|
|
$script:CiVmId = $vm.VmId
|
|
|
|
# Add a cloud-init drive
|
|
Set-PveVmConfig -Node $script:Node -VmId $script:CiVmId `
|
|
-AdditionalConfig @{ ide2 = "$($script:Storage):cloudinit" } `
|
|
-ErrorAction Stop
|
|
}
|
|
}
|
|
|
|
Context 'Cloud-Init' {
|
|
It 'Should get cloud-init config' {
|
|
if (Skip-IfNoCiVm) { return }
|
|
|
|
{ Get-PveCloudInitConfig -Node $script:Node -VmId $script:CiVmId -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
}
|
|
|
|
It 'Should set cloud-init config' {
|
|
if (Skip-IfNoCiVm) { return }
|
|
|
|
{ Set-PveCloudInitConfig -Node $script:Node -VmId $script:CiVmId `
|
|
-CiUser 'pester-user' -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
|
|
$config = Get-PveCloudInitConfig -Node $script:Node -VmId $script:CiVmId -ErrorAction Stop
|
|
$config.CiUser | Should -Be 'pester-user'
|
|
}
|
|
|
|
It 'Should regenerate cloud-init image' {
|
|
if (Skip-IfNoCiVm) { return }
|
|
|
|
{ Invoke-PveCloudInitRegenerate -Node $script:Node -VmId $script:CiVmId -Wait -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
}
|
|
}
|
|
}
|