mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-12 15:16:52 +00:00
a72642d203
Add 35 new cmdlets bringing the total to 118: - Firewall (21): rules, groups, aliases, IP sets, options at cluster/node/VM/container levels - Backup (5): ad-hoc vzdump and scheduled backup job CRUD - SDN IPAM/DNS/Controller (9): plugin management for SDN subsystem Also includes: - Fix: Remove-PveRole now has ConfirmImpact.High - Fix: URL-encode snapshot names in API paths - Refactor: extract auth header strings to constants in PveHttpClient - Add PSGallery version badge to README - Full test coverage: 11 JSON fixtures, xUnit model tests, Pester unit tests, and integration tests for firewall/backup/OVA import - Updated manifest, format file, CHANGELOG, README, API coverage docs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
177 lines
6.3 KiB
PowerShell
177 lines
6.3 KiB
PowerShell
#Requires -Module Pester
|
|
<#
|
|
.SYNOPSIS
|
|
Pester 5 tests for firewall group cmdlets:
|
|
Get-PveFirewallGroup, New-PveFirewallGroup, Remove-PveFirewallGroup.
|
|
|
|
All tests are fully offline — no live Proxmox VE target is required.
|
|
If a cmdlet is not yet compiled the test is marked Skipped.
|
|
#>
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/../_TestHelper.ps1
|
|
|
|
$script:Availability = @{}
|
|
foreach ($name in @('Get-PveFirewallGroup', 'New-PveFirewallGroup', 'Remove-PveFirewallGroup')) {
|
|
$script:Availability[$name] = $null -ne (Get-Command $name -ErrorAction SilentlyContinue)
|
|
}
|
|
|
|
function Skip-IfMissing([string]$Name) {
|
|
if (-not $script:Availability[$Name]) {
|
|
Set-ItResult -Skipped -Because "$Name is not yet implemented in this build"
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Manifest contract
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Firewall group cmdlets — manifest declarations' {
|
|
BeforeAll {
|
|
$manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1'
|
|
$script:Manifest = if (Test-Path $manifestPath) { Import-PowerShellDataFile $manifestPath } else { $null }
|
|
}
|
|
|
|
It "<cmdName> should be declared in CmdletsToExport" -TestCases @(
|
|
@{ cmdName = 'Get-PveFirewallGroup' }
|
|
@{ cmdName = 'New-PveFirewallGroup' }
|
|
@{ cmdName = 'Remove-PveFirewallGroup' }
|
|
) {
|
|
if ($null -eq $script:Manifest) { Set-ItResult -Skipped -Because 'Manifest not found'; return }
|
|
$script:Manifest.CmdletsToExport | Should -Contain $cmdName
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Get-PveFirewallGroup
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Get-PveFirewallGroup' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Get-PveFirewallGroup' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Get-PveFirewallGroup'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should be a CmdletInfo (binary cmdlet)' {
|
|
Skip-IfMissing 'Get-PveFirewallGroup'
|
|
$script:Cmd.CommandType | Should -Be 'Cmdlet'
|
|
}
|
|
}
|
|
|
|
Context 'Parameter metadata' {
|
|
It 'Should have optional Group parameter' {
|
|
Skip-IfMissing 'Get-PveFirewallGroup'
|
|
$script:Cmd.Parameters.ContainsKey('Group') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have Session parameter' {
|
|
Skip-IfMissing 'Get-PveFirewallGroup'
|
|
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Without active session' {
|
|
It 'Should throw when no session is active' {
|
|
Skip-IfMissing 'Get-PveFirewallGroup'
|
|
{ Get-PveFirewallGroup -ErrorAction Stop } |
|
|
Should -Throw '*No active Proxmox VE session*'
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# New-PveFirewallGroup
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'New-PveFirewallGroup' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'New-PveFirewallGroup' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'New-PveFirewallGroup'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess support' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'New-PveFirewallGroup'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Group should be Mandatory' {
|
|
Skip-IfMissing 'New-PveFirewallGroup'
|
|
$isMandatory = $script:Cmd.Parameters['Group'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'Optional parameters' {
|
|
It 'Should have Comment parameter' {
|
|
Skip-IfMissing 'New-PveFirewallGroup'
|
|
$script:Cmd.Parameters.ContainsKey('Comment') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Without active session' {
|
|
It 'Should throw when no session is active' {
|
|
Skip-IfMissing 'New-PveFirewallGroup'
|
|
{ New-PveFirewallGroup -Group 'testgroup' -ErrorAction Stop } |
|
|
Should -Throw '*No active Proxmox VE session*'
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Remove-PveFirewallGroup
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Remove-PveFirewallGroup' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Remove-PveFirewallGroup' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Remove-PveFirewallGroup'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess / ConfirmImpact' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'Remove-PveFirewallGroup'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should declare ConfirmImpact High' {
|
|
Skip-IfMissing 'Remove-PveFirewallGroup'
|
|
$attr = $script:Cmd.ImplementingType.GetCustomAttributes(
|
|
[System.Management.Automation.CmdletAttribute], $false) |
|
|
Select-Object -First 1
|
|
$attr.ConfirmImpact | Should -Be ([System.Management.Automation.ConfirmImpact]::High)
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Group should be Mandatory' {
|
|
Skip-IfMissing 'Remove-PveFirewallGroup'
|
|
$isMandatory = $script:Cmd.Parameters['Group'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'Without active session' {
|
|
It 'Should throw when no session is active' {
|
|
Skip-IfMissing 'Remove-PveFirewallGroup'
|
|
{ Remove-PveFirewallGroup -Group 'testgroup' -Confirm:$false -ErrorAction Stop } |
|
|
Should -Throw '*No active Proxmox VE session*'
|
|
}
|
|
}
|
|
}
|