Files
PSProxmoxVE/tests/PSProxmoxVE.Tests/Containers/Get-PveContainer.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

96 lines
3.9 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for Get-PveContainer.
All tests are fully offline — no live Proxmox VE target is required.
Get-PveContainer mirrors the design of Get-PveVm for LXC containers.
If the cmdlet is not yet implemented (dll compiled without it), tests
that depend on invocation are marked Skipped rather than Failed.
#>
BeforeAll {
. $PSScriptRoot/../_TestHelper.ps1
$script:CmdExists = $null -ne (Get-Command 'Get-PveContainer' -ErrorAction SilentlyContinue)
}
Describe 'Get-PveContainer' {
Context 'Command existence' {
It 'Get-PveContainer should be listed in the module manifest CmdletsToExport' {
# The .psd1 declares the cmdlet; implementation may be pending.
$manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1'
if (Test-Path $manifestPath) {
$manifest = Import-PowerShellDataFile $manifestPath
$manifest.CmdletsToExport | Should -Contain 'Get-PveContainer'
}
else {
Set-ItResult -Skipped -Because 'Module manifest not found at expected path'
}
}
It 'Should be available after module import (or skip if not yet compiled)' {
if (-not $script:CmdExists) {
Set-ItResult -Skipped -Because 'Get-PveContainer is not yet implemented in this build'
return
}
(Get-Command 'Get-PveContainer').CommandType | Should -Be 'Cmdlet'
}
}
Context 'Parameter metadata' {
BeforeAll {
$script:Cmd = Get-Command 'Get-PveContainer' -ErrorAction SilentlyContinue
}
It 'Should have Node parameter' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue
}
It 'Node should not be Mandatory (all-nodes query when omitted)' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'Should have VmId parameter' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue
}
It 'Should have Name parameter' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$script:Cmd.Parameters.ContainsKey('Name') | Should -BeTrue
}
It 'Should have Status parameter' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$script:Cmd.Parameters.ContainsKey('Status') | Should -BeTrue
}
It 'Should have Session parameter (inherited from PveCmdletBase)' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
}
It 'Node should accept pipeline input by property name' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
$node = $script:Cmd.Parameters['Node']
$acceptsByPropName = $node.ParameterSets.Values |
Where-Object { $_.ValueFromPipelineByPropertyName }
$acceptsByPropName | Should -Not -BeNullOrEmpty
}
}
Context 'Without active session' {
It 'Should throw when no session is active' {
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
{ Get-PveContainer -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
}
}