fix(ci): align all projects on net9.0, upgrade actions to v5, enable VM tests

- Change test projects from net10.0 to net9.0 to match source projects
- Update build workflow from net8.0 to net9.0
- Upgrade checkout to v5, setup-dotnet to v5 across all workflows
- Remove outdated PS 7.2 test matrix entries
- Restructure integration tests: create test keeps VM alive so start/stop,
  snapshot, and cloud-init tests can use it instead of skipping. AfterAll
  handles cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-18 16:59:43 -05:00
parent 8779dc5818
commit b64c34c8cd
7 changed files with 53 additions and 85 deletions
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net10.0;net48</TargetFrameworks>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
@@ -77,7 +77,7 @@ BeforeAll {
# Track resources created during the run so AfterAll can clean up.
$script:CreatedVmIds = [System.Collections.Generic.List[int]]::new()
$script:CreatedVmSnaps = [System.Collections.Generic.List[hashtable]]::new()
$script:TestVmId = $null
}
AfterAll {
@@ -85,6 +85,8 @@ AfterAll {
if ($null -eq $script:SkipReason -and $script:CreatedVmIds.Count -gt 0) {
foreach ($vmId in $script:CreatedVmIds) {
try {
Stop-PveVm -Node $script:Node -VmId $vmId -ErrorAction SilentlyContinue | Out-Null
Start-Sleep -Seconds 3
Remove-PveVm -Node $script:Node -VmId $vmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue
}
catch { <# non-fatal #> }
@@ -153,7 +155,7 @@ Describe 'Integration Tests' -Tag 'Integration' {
{ Get-PveVm -Node $script:Node -ErrorAction Stop } | Should -Not -Throw
}
It 'Should create and remove a test VM' {
It 'Should create a test VM' {
if ($script:SkipReason) { Set-ItResult -Skipped -Because $script:SkipReason; return }
$task = New-PveVm `
@@ -170,34 +172,22 @@ Describe 'Integration Tests' -Tag 'Integration' {
Select-Object -First 1
$vm | Should -Not -BeNullOrEmpty
$script:TestVmId = $vm.VmId
$script:CreatedVmIds.Add($vm.VmId)
$removeTask = Remove-PveVm `
-Node $script:Node `
-VmId $vm.VmId `
-Confirm:$false `
-Wait
$removeTask | Should -Not -BeNullOrEmpty
$script:CreatedVmIds.Remove($vm.VmId) | Out-Null
}
It 'Should start and stop a VM' {
if ($script:SkipReason) { Set-ItResult -Skipped -Because $script:SkipReason; return }
# Requires at least one VM on the test node; skip if none found.
$vm = Get-PveVm -Node $script:Node | Where-Object { $_.Status -eq 'stopped' } |
Select-Object -First 1
if ($null -eq $vm) {
Set-ItResult -Skipped -Because 'No stopped VM available on the test node'
if ($null -eq $script:TestVmId) {
Set-ItResult -Skipped -Because 'No test VM was created'
return
}
$startTask = Start-PveVm -Node $script:Node -VmId $vm.VmId -Wait
$startTask = Start-PveVm -Node $script:Node -VmId $script:TestVmId -Wait
$startTask | Should -Not -BeNullOrEmpty
$stopTask = Stop-PveVm -Node $script:Node -VmId $vm.VmId -Wait
$stopTask = Stop-PveVm -Node $script:Node -VmId $script:TestVmId -Wait
$stopTask | Should -Not -BeNullOrEmpty
}
@@ -260,31 +250,34 @@ Describe 'Integration Tests' -Tag 'Integration' {
It 'Should create and remove a snapshot' {
if ($script:SkipReason) { Set-ItResult -Skipped -Because $script:SkipReason; return }
$vm = Get-PveVm -Node $script:Node | Where-Object { $_.Status -eq 'stopped' } |
Select-Object -First 1
if ($null -eq $vm) {
Set-ItResult -Skipped -Because 'No stopped VM available for snapshot test'
if ($null -eq $script:TestVmId) {
Set-ItResult -Skipped -Because 'No test VM was created'
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 | Out-Null
}
$snapName = 'pester-snap'
$createTask = New-PveSnapshot `
-Node $script:Node `
-VmId $vm.VmId `
-VmId $script:TestVmId `
-Name $snapName `
-Description 'Created by Pester integration test' `
-Wait
$createTask | Should -Not -BeNullOrEmpty
$snapshots = Get-PveSnapshot -Node $script:Node -VmId $vm.VmId
$snapshots = Get-PveSnapshot -Node $script:Node -VmId $script:TestVmId
$snapshots | Where-Object { $_.Name -eq $snapName } | Should -Not -BeNullOrEmpty
$removeTask = Remove-PveSnapshot `
-Node $script:Node `
-VmId $vm.VmId `
-VmId $script:TestVmId `
-Name $snapName `
-Confirm:$false `
-Wait
@@ -330,16 +323,13 @@ Describe 'Integration Tests' -Tag 'Integration' {
It 'Should get cloud-init config' {
if ($script:SkipReason) { Set-ItResult -Skipped -Because $script:SkipReason; return }
$ciVm = Get-PveVm -Node $script:Node | Where-Object { $_.Status -eq 'stopped' } |
Select-Object -First 1
if ($null -eq $ciVm) {
Set-ItResult -Skipped -Because 'No stopped VM available for cloud-init test'
if ($null -eq $script:TestVmId) {
Set-ItResult -Skipped -Because 'No test VM available for cloud-init test'
return
}
# Get-PveCloudInitConfig should not throw even if the VM has no cloud-init drive.
{ Get-PveCloudInitConfig -Node $script:Node -VmId $ciVm.VmId -ErrorAction Stop } |
{ Get-PveCloudInitConfig -Node $script:Node -VmId $script:TestVmId -ErrorAction Stop } |
Should -Not -Throw
}
}