Files
PSProxmoxVE/tests/PSProxmoxVE.Tests/Vms/Get-PveVm.Tests.ps1
T
Clint Branham 0dc7f5f833 fix(test): fix assembly loading, remove mock server, resolve test warnings
- Create shared _TestHelper.ps1 for reliable module loading in both
  local dev and CI (fixes System.Runtime 9.0.0.0 FileNotFoundException
  on PS 7.x by trying Import-Module by name first, then local paths)
- Use (Get-Module).ModuleBase for manifest path resolution
- Remove PSProxmoxVE.MockServer project and MockIntegration tests
- Remove MockIntegration from ExcludeTag filters

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

98 lines
3.3 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for Get-PveVm.
All tests are fully offline — no live Proxmox VE target is required.
#>
BeforeAll {
. $PSScriptRoot/../_TestHelper.ps1
}
Describe 'Get-PveVm' {
Context 'Command existence' {
It 'Should be available after module import' {
Get-Command 'Get-PveVm' -ErrorAction SilentlyContinue |
Should -Not -BeNullOrEmpty
}
It 'Should be a CmdletInfo (binary cmdlet)' {
(Get-Command 'Get-PveVm').CommandType | Should -Be 'Cmdlet'
}
}
Context 'Parameter validation' {
BeforeAll {
$script:Cmd = Get-Command 'Get-PveVm'
}
It 'Should have Node parameter' {
$script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue
}
It 'Node should not be Mandatory (all-nodes query when omitted)' {
$node = $script:Cmd.Parameters['Node']
$isMandatory = $node.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Node should accept pipeline input by property name' {
$node = $script:Cmd.Parameters['Node']
$acceptsByPropName = $node.ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
It 'Should have VmId parameter' {
$script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue
}
It 'Should have Name parameter' {
$script:Cmd.Parameters.ContainsKey('Name') | Should -BeTrue
}
It 'Should have Status parameter' {
$script:Cmd.Parameters.ContainsKey('Status') | Should -BeTrue
}
It 'Should have Tag parameter' {
$script:Cmd.Parameters.ContainsKey('Tag') | Should -BeTrue
}
It 'Should have TemplatesOnly switch parameter' {
$script:Cmd.Parameters.ContainsKey('TemplatesOnly') | Should -BeTrue
$script:Cmd.Parameters['TemplatesOnly'].ParameterType |
Should -Be ([System.Management.Automation.SwitchParameter])
}
It 'Should have Session parameter (inherited from PveCmdletBase)' {
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
}
It 'None of the filter parameters should be Mandatory' {
foreach ($paramName in @('Node', 'VmId', 'Name', 'Status', 'Tag', 'TemplatesOnly', 'Session')) {
$p = $script:Cmd.Parameters[$paramName]
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty -Because "$paramName should be optional"
}
}
}
Context 'Without active session' {
It 'Should throw when no session is active and no -Session is supplied' {
{ Get-PveVm -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
It 'Should throw PveNotConnectedException type' {
try {
Get-PveVm -ErrorAction Stop
}
catch {
$_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException'
}
}
}
}