From d99c3e5490726ca7ba6c2258abad82dccabd96f9 Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Sun, 22 Mar 2026 08:16:45 -0500 Subject: [PATCH] chore(test): update tests for parameter changes, target net10.0 - xUnit test project now targets net10.0 instead of net9.0 (EOL Nov 2026) - Updated GuestAgentExtCmdlets tests for SecureString Password parameter - Added Timeout parameter tests to GuestAgentCmdlets - Added ConfirmImpact.High assertions for Suspend/Restart-PveVm - Added -Confirm:$false to Suspend-PveVm integration test call Co-Authored-By: Claude Opus 4.6 (1M context) --- .../PSProxmoxVE.Core.Tests.csproj | 2 +- .../Integration/Integration.Tests.ps1 | 2 +- .../Vms/GuestAgentCmdlets.Tests.ps1 | 15 +++++++++++++++ .../Vms/GuestAgentExtCmdlets.Tests.ps1 | 11 ++++++++++- .../Vms/VmLifecycle.Tests.ps1 | 18 ++++++++++++++++-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/PSProxmoxVE.Core.Tests/PSProxmoxVE.Core.Tests.csproj b/tests/PSProxmoxVE.Core.Tests/PSProxmoxVE.Core.Tests.csproj index a83780d..3b9383c 100644 --- a/tests/PSProxmoxVE.Core.Tests/PSProxmoxVE.Core.Tests.csproj +++ b/tests/PSProxmoxVE.Core.Tests/PSProxmoxVE.Core.Tests.csproj @@ -1,7 +1,7 @@ - net9.0;net48 + net10.0;net48 10.0 enable false diff --git a/tests/PSProxmoxVE.Tests/Integration/Integration.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/Integration.Tests.ps1 index 34b5103..0013735 100644 --- a/tests/PSProxmoxVE.Tests/Integration/Integration.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/Integration.Tests.ps1 @@ -1210,7 +1210,7 @@ Describe 'Integration Tests' -Tag 'Integration' { if (Skip-IfNoLinuxVm) { return } # Suspend — -Wait -Timeout polls qmpstatus until 'paused' - $suspendTask = Suspend-PveVm -Node $script:Node -VmId $script:LinuxVmId -Wait -Timeout 30 + $suspendTask = Suspend-PveVm -Node $script:Node -VmId $script:LinuxVmId -Wait -Timeout 30 -Confirm:$false $suspendTask | Should -Not -BeNullOrEmpty # Verify with -Detailed (fetches qmpstatus from status/current endpoint) diff --git a/tests/PSProxmoxVE.Tests/Vms/GuestAgentCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/GuestAgentCmdlets.Tests.ps1 index 1f10b31..bfe6943 100644 --- a/tests/PSProxmoxVE.Tests/Vms/GuestAgentCmdlets.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Vms/GuestAgentCmdlets.Tests.ps1 @@ -202,6 +202,21 @@ Describe 'Invoke-PveVmGuestExec' { Where-Object { $_.IsMandatory } $isMandatory | Should -Not -BeNullOrEmpty } + + It 'Should have Timeout parameter of type int' { + Skip-IfMissing 'Invoke-PveVmGuestExec' + $script:Cmd.Parameters.ContainsKey('Timeout') | Should -BeTrue + $script:Cmd.Parameters['Timeout'].ParameterType | Should -Be ([int]) + } + + It 'Timeout should have ValidateRange(1,3600)' { + Skip-IfMissing 'Invoke-PveVmGuestExec' + $rangeAttr = $script:Cmd.Parameters['Timeout'].Attributes | + Where-Object { $_ -is [System.Management.Automation.ValidateRangeAttribute] } + $rangeAttr | Should -Not -BeNullOrEmpty + $rangeAttr.MinRange | Should -Be 1 + $rangeAttr.MaxRange | Should -Be 3600 + } } Context 'Without active session' { diff --git a/tests/PSProxmoxVE.Tests/Vms/GuestAgentExtCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/GuestAgentExtCmdlets.Tests.ps1 index f394654..3ad76e4 100644 --- a/tests/PSProxmoxVE.Tests/Vms/GuestAgentExtCmdlets.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Vms/GuestAgentExtCmdlets.Tests.ps1 @@ -272,10 +272,19 @@ Describe 'Set-PveVmGuestPassword' -Tag 'Unit' { } } + Context 'Parameter types' { + It 'Password should be SecureString' { + Skip-IfMissing 'Set-PveVmGuestPassword' + $script:Cmd.Parameters['Password'].ParameterType | + Should -Be ([System.Security.SecureString]) + } + } + Context 'Without active session' { It 'Should throw when no session is active' { Skip-IfMissing 'Set-PveVmGuestPassword' - { Set-PveVmGuestPassword -Node 'pve' -VmId 100 -Username 'root' -Password 'dummy' -ErrorAction Stop } | + $secPwd = ConvertTo-SecureString 'dummy' -AsPlainText -Force + { Set-PveVmGuestPassword -Node 'pve' -VmId 100 -Username 'root' -Password $secPwd -ErrorAction Stop } | Should -Throw '*No active Proxmox VE session*' } } diff --git a/tests/PSProxmoxVE.Tests/Vms/VmLifecycle.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/VmLifecycle.Tests.ps1 index 929b27e..697ee5b 100644 --- a/tests/PSProxmoxVE.Tests/Vms/VmLifecycle.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Vms/VmLifecycle.Tests.ps1 @@ -165,11 +165,18 @@ Describe 'Suspend-PveVm' { It 'Should support ShouldProcess' { $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue } + + It 'Should declare ConfirmImpact High' { + $attr = $script:Cmd.ImplementingType.GetCustomAttributes( + [System.Management.Automation.CmdletAttribute], $false) | + Select-Object -First 1 + $attr.ConfirmImpact | Should -Be ([System.Management.Automation.ConfirmImpact]::High) + } } Context 'Without active session' { It 'Should throw when no session is active (without -WhatIf)' { - { Suspend-PveVm -Node 'pve-node1' -VmId 100 -ErrorAction Stop } | + { Suspend-PveVm -Node 'pve-node1' -VmId 100 -Confirm:$false -ErrorAction Stop } | Should -Throw '*No active Proxmox VE session*' } } @@ -303,11 +310,18 @@ Describe 'Restart-PveVm' { It 'Should support ShouldProcess' { $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue } + + It 'Should declare ConfirmImpact High' { + $attr = $script:Cmd.ImplementingType.GetCustomAttributes( + [System.Management.Automation.CmdletAttribute], $false) | + Select-Object -First 1 + $attr.ConfirmImpact | Should -Be ([System.Management.Automation.ConfirmImpact]::High) + } } Context 'Without active session' { It 'Should throw when no session is active (without -WhatIf)' { - { Restart-PveVm -Node 'pve-node1' -VmId 100 -ErrorAction Stop } | + { Restart-PveVm -Node 'pve-node1' -VmId 100 -Confirm:$false -ErrorAction Stop } | Should -Throw '*No active Proxmox VE session*' }