Files
Clint Branham 3075c12768 test: add unit tests for all previously untested cmdlets (274 new tests)
Coverage for 16 cmdlets that had no unit tests:
- Nodes: Get-PveNode, Get-PveNodeStatus
- VM config: Get-PveVmConfig, Set-PveVmConfig, Resize-PveVmDisk
- VM ops: Copy-PveVm, Move-PveVm
- Container config: Copy-PveContainer, Get-PveContainerConfig,
  Set-PveContainerConfig
- Storage: Invoke-PveStorageDownload
- Roles: New-PveRole, Remove-PveRole
- Tasks: Get-PveTask, Wait-PveTask

Each test covers: command existence, parameter metadata, pipeline
support, ShouldProcess/WhatIf, and no-session error handling.

Total Pester unit tests: 705 (was 431)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 18:15:17 -05:00

171 lines
5.7 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for Get-PveNode and Get-PveNodeStatus.
All tests are fully offline — no live Proxmox VE target is required.
#>
BeforeAll {
. $PSScriptRoot/../_TestHelper.ps1
}
# ---------------------------------------------------------------------------
# Get-PveNode
# ---------------------------------------------------------------------------
Describe 'Get-PveNode' {
Context 'Command existence' {
It 'Should be available after module import' {
Get-Command 'Get-PveNode' -ErrorAction SilentlyContinue |
Should -Not -BeNullOrEmpty
}
It 'Should be a CmdletInfo (binary cmdlet)' {
(Get-Command 'Get-PveNode').CommandType | Should -Be 'Cmdlet'
}
}
Context 'Parameter validation' {
BeforeAll {
$script:Cmd = Get-Command 'Get-PveNode'
}
It 'Should have Name parameter' {
$script:Cmd.Parameters.ContainsKey('Name') | Should -BeTrue
}
It 'Name should not be Mandatory' {
$p = $script:Cmd.Parameters['Name']
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Name should be at Position 0' {
$p = $script:Cmd.Parameters['Name']
$pos = $p.ParameterSets.Values | ForEach-Object { $_.Position }
$pos | Should -Contain 0
}
It 'Name should be of type String' {
$script:Cmd.Parameters['Name'].ParameterType | Should -Be ([string])
}
It 'Should have Session parameter (inherited from PveCmdletBase)' {
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
}
It 'Session should not be Mandatory' {
$p = $script:Cmd.Parameters['Session']
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should declare PveNode as OutputType' {
$outputTypes = $script:Cmd.OutputType.Type
$outputTypes.Name | Should -Contain 'PveNode'
}
}
Context 'Without active session' {
It 'Should throw when no session is active and no -Session is supplied' {
{ Get-PveNode -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Get-PveNode -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
}
}
# ---------------------------------------------------------------------------
# Get-PveNodeStatus
# ---------------------------------------------------------------------------
Describe 'Get-PveNodeStatus' {
Context 'Command existence' {
It 'Should be available after module import' {
Get-Command 'Get-PveNodeStatus' -ErrorAction SilentlyContinue |
Should -Not -BeNullOrEmpty
}
It 'Should be a CmdletInfo (binary cmdlet)' {
(Get-Command 'Get-PveNodeStatus').CommandType | Should -Be 'Cmdlet'
}
}
Context 'Parameter validation' {
BeforeAll {
$script:Cmd = Get-Command 'Get-PveNodeStatus'
}
It 'Should have Node parameter' {
$script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue
}
It 'Node should be Mandatory' {
$p = $script:Cmd.Parameters['Node']
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Node should be at Position 0' {
$p = $script:Cmd.Parameters['Node']
$pos = $p.ParameterSets.Values | ForEach-Object { $_.Position }
$pos | Should -Contain 0
}
It 'Node should be of type String' {
$script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string])
}
It 'Node should accept pipeline input by property name' {
$p = $script:Cmd.Parameters['Node']
$acceptsByPropName = $p.ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'Should have Session parameter (inherited from PveCmdletBase)' {
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
}
It 'Session should not be Mandatory' {
$p = $script:Cmd.Parameters['Session']
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should declare PveNodeStatus as OutputType' {
$outputTypes = $script:Cmd.OutputType.Type
$outputTypes.Name | Should -Contain 'PveNodeStatus'
}
}
Context 'Without active session' {
It 'Should throw when no session is active and no -Session is supplied' {
{ Get-PveNodeStatus -Node 'pve1' -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Get-PveNodeStatus -Node 'pve1' -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
It 'Should require the Node parameter' {
{ Get-PveNodeStatus -ErrorAction Stop } |
Should -Throw '*Node*'
}
}
}