Files
PSProxmoxVE/tests/PSProxmoxVE.Tests/Vms/VmConfigCmdlets.Tests.ps1
T
goodolclint-claude[bot] 109dca657a refactor: make the offline Pester suite able to fail (#153) (#205)
Skip-IfMissing skipped a test whenever the cmdlet under test was absent
from the build, including the test asserting it exists. Every cmdlet
compiles into one assembly, so there is no partial-build case for it to
serve; all it did was hide a missing cmdlet. Delete the 37 copies and
every call site, and drop the residual conditional skips in the same
family (CmdExists probes, an attribute-presence skip in SdnCmdlets, a
lifecycle helper skipping on a cmdlet-name collision fixed long ago).

894 It blocks only reflected [Cmdlet] and [Parameter] attributes back at
the compiler: existence, CommandType -eq 'Cmdlet', Parameters.ContainsKey,
IsMandatory reflection, and per-file CmdletsToExport asserts for whichever
names an author remembered. Nothing reflected over the built assembly, so
a new cmdlet missing from the manifest shipped invisible. One data-driven
file replaces them: it diffs CmdletsToExport against the assembly's cmdlet
types in both directions and asserts the conventions reflection can see.

Behavioural tests are untouched: no-session errors, binding rejections,
ShouldProcess and -WhatIf, ConfirmImpact, ValidateSet and ValidateRange
values, parameter types, positions and pipeline binding.

The generated help covered 169 of 194 cmdlets. Regenerated with the repo's
own generate-help.ps1: 25 new markdown stubs, 13 existing docs picking up
parameters added in earlier waves, and a rebuilt MAML.

Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
2026-09-03 00:54:02 +00:00

280 lines
11 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for VM configuration cmdlets:
Get-PveVmConfig, Set-PveVmConfig, Resize-PveVmDisk.
All tests are fully offline — no live Proxmox VE target is required.
#>
BeforeAll {
. $PSScriptRoot/../_TestHelper.ps1
}
# ---------------------------------------------------------------------------
# Get-PveVmConfig
# ---------------------------------------------------------------------------
Describe 'Get-PveVmConfig' {
Context 'Parameter metadata' {
BeforeAll {
$script:Cmd = Get-Command 'Get-PveVmConfig'
}
It 'Node should be of type String' {
$script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string])
}
It 'Node should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'VmId should be of type Int32' {
$script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int])
}
It 'VmId should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'Should not support ShouldProcess (read-only cmdlet)' {
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeFalse
}
}
Context 'Without active session' {
It 'Should throw when no session is active and no -Session is supplied' {
{ Get-PveVmConfig -Node 'pve-node1' -VmId 100 -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Get-PveVmConfig -Node 'pve-node1' -VmId 100 -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
}
}
# ---------------------------------------------------------------------------
# Set-PveVmConfig
# ---------------------------------------------------------------------------
Describe 'Set-PveVmConfig' {
Context 'Parameter metadata' {
BeforeAll {
$script:Cmd = Get-Command 'Set-PveVmConfig'
}
It 'Node should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'VmId should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
# Configuration parameters — all optional
It 'Should have Cores parameter (optional, Int32)' {
$script:Cmd.Parameters.ContainsKey('Cores') | Should -BeTrue
$script:Cmd.Parameters['Cores'].ParameterType |
Should -Be ([System.Nullable[int]])
$isMandatory = $script:Cmd.Parameters['Cores'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have Sockets parameter (optional, Int32)' {
$script:Cmd.Parameters.ContainsKey('Sockets') | Should -BeTrue
$script:Cmd.Parameters['Sockets'].ParameterType |
Should -Be ([System.Nullable[int]])
$isMandatory = $script:Cmd.Parameters['Sockets'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have Memory parameter (optional, Int32)' {
$script:Cmd.Parameters.ContainsKey('Memory') | Should -BeTrue
$script:Cmd.Parameters['Memory'].ParameterType |
Should -Be ([System.Nullable[int]])
$isMandatory = $script:Cmd.Parameters['Memory'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have CpuType parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('CpuType') | Should -BeTrue
$script:Cmd.Parameters['CpuType'].ParameterType | Should -Be ([string])
$isMandatory = $script:Cmd.Parameters['CpuType'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have Description parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('Description') | Should -BeTrue
$script:Cmd.Parameters['Description'].ParameterType | Should -Be ([string])
}
It 'Should have Tags parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('Tags') | Should -BeTrue
$script:Cmd.Parameters['Tags'].ParameterType | Should -Be ([string])
}
It 'Should have Bios parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('Bios') | Should -BeTrue
$script:Cmd.Parameters['Bios'].ParameterType | Should -Be ([string])
}
It 'Should have Machine parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('Machine') | Should -BeTrue
$script:Cmd.Parameters['Machine'].ParameterType | Should -Be ([string])
}
It 'Should have OsType parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('OsType') | Should -BeTrue
$script:Cmd.Parameters['OsType'].ParameterType | Should -Be ([string])
}
It 'Should have AdditionalConfig parameter (optional, Hashtable)' {
$script:Cmd.Parameters.ContainsKey('AdditionalConfig') | Should -BeTrue
$script:Cmd.Parameters['AdditionalConfig'].ParameterType | Should -Be ([hashtable])
$isMandatory = $script:Cmd.Parameters['AdditionalConfig'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have Delete parameter (optional, String)' {
$script:Cmd.Parameters.ContainsKey('Delete') | Should -BeTrue
$script:Cmd.Parameters['Delete'].ParameterType | Should -Be ([string])
$isMandatory = $script:Cmd.Parameters['Delete'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
}
Context 'ShouldProcess support' {
It 'Should support ShouldProcess (WhatIf parameter exists)' {
$cmd = Get-Command 'Set-PveVmConfig'
$cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
}
It 'Should support Confirm parameter' {
$cmd = Get-Command 'Set-PveVmConfig'
$cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue
}
It 'Should not throw with -WhatIf (no session required)' {
{ Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Memory 4096 -WhatIf -ErrorAction Stop } |
Should -Not -Throw
}
It 'Should not throw with -WhatIf and multiple config params' {
{ Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Cores 4 -Sockets 2 -Memory 8192 -WhatIf -ErrorAction Stop } |
Should -Not -Throw
}
}
Context 'Without active session' {
It 'Should throw when no session is active (without -WhatIf)' {
{ Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Memory 4096 -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Cores 2 -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
}
}
# ---------------------------------------------------------------------------
# Resize-PveVmDisk
# ---------------------------------------------------------------------------
Describe 'Resize-PveVmDisk' {
Context 'Parameter metadata' {
BeforeAll {
$script:Cmd = Get-Command 'Resize-PveVmDisk'
}
It 'Node should be of type String' {
$script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string])
}
It 'Node should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'VmId should be of type Int32' {
$script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int])
}
It 'VmId should accept pipeline input by property name' {
$acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'Disk should be of type String' {
$script:Cmd.Parameters['Disk'].ParameterType | Should -Be ([string])
}
It 'Size should be of type String' {
$script:Cmd.Parameters['Size'].ParameterType | Should -Be ([string])
}
It 'Should have Wait switch parameter' {
$script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue
$script:Cmd.Parameters['Wait'].ParameterType |
Should -Be ([System.Management.Automation.SwitchParameter])
}
}
Context 'ShouldProcess support' {
It 'Should support ShouldProcess (WhatIf parameter exists)' {
$cmd = Get-Command 'Resize-PveVmDisk'
$cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
}
It 'Should support Confirm parameter' {
$cmd = Get-Command 'Resize-PveVmDisk'
$cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue
}
It 'Should not throw with -WhatIf (no session required)' {
{ Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'scsi0' -Size '+10G' -WhatIf -ErrorAction Stop } |
Should -Not -Throw
}
}
Context 'Without active session' {
It 'Should throw when no session is active (without -WhatIf)' {
{ Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'scsi0' -Size '50G' -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'virtio0' -Size '+5G' -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
}
}