fix(test): fix 16 Pester unit test failures in firewall cmdlets

- Add -Level Cluster to "no session" tests for cmdlets that require
  the mandatory Level parameter (13 failures)
- Fix parameter name Pos → Position in Set/Remove-PveFirewallRule
  tests (2 failures)
- Change Set-PveFirewallAlias Cidr test from mandatory to optional
  assertion — Cidr is optional on update (1 failure)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-21 08:48:36 -05:00
parent 27ecca6251
commit b11f41a5cc
4 changed files with 20 additions and 22 deletions
@@ -77,7 +77,7 @@ Describe 'Get-PveFirewallAlias' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Get-PveFirewallAlias' Skip-IfMissing 'Get-PveFirewallAlias'
{ Get-PveFirewallAlias -ErrorAction Stop } | { Get-PveFirewallAlias -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -130,7 +130,7 @@ Describe 'New-PveFirewallAlias' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'New-PveFirewallAlias' Skip-IfMissing 'New-PveFirewallAlias'
{ New-PveFirewallAlias -Name 'testalias' -Cidr '10.0.0.0/24' -ErrorAction Stop } | { New-PveFirewallAlias -Name 'testalias' -Cidr '10.0.0.0/24' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -165,18 +165,16 @@ Describe 'Set-PveFirewallAlias' {
$isMandatory | Should -Not -BeNullOrEmpty $isMandatory | Should -Not -BeNullOrEmpty
} }
It 'Cidr should be Mandatory' { It 'Should have optional Cidr parameter' {
Skip-IfMissing 'Set-PveFirewallAlias' Skip-IfMissing 'Set-PveFirewallAlias'
$isMandatory = $script:Cmd.Parameters['Cidr'].ParameterSets.Values | $script:Cmd.Parameters.ContainsKey('Cidr') | Should -BeTrue
Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
} }
} }
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Set-PveFirewallAlias' Skip-IfMissing 'Set-PveFirewallAlias'
{ Set-PveFirewallAlias -Name 'testalias' -Cidr '10.0.0.0/24' -ErrorAction Stop } | { Set-PveFirewallAlias -Name 'testalias' -Cidr '10.0.0.0/24' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -223,7 +221,7 @@ Describe 'Remove-PveFirewallAlias' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Remove-PveFirewallAlias' Skip-IfMissing 'Remove-PveFirewallAlias'
{ Remove-PveFirewallAlias -Name 'testalias' -Confirm:$false -ErrorAction Stop } | { Remove-PveFirewallAlias -Name 'testalias' -Confirm:$false -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -86,7 +86,7 @@ Describe 'Get-PveFirewallIpSet' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Get-PveFirewallIpSet' Skip-IfMissing 'Get-PveFirewallIpSet'
{ Get-PveFirewallIpSet -ErrorAction Stop } | { Get-PveFirewallIpSet -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -132,7 +132,7 @@ Describe 'New-PveFirewallIpSet' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'New-PveFirewallIpSet' Skip-IfMissing 'New-PveFirewallIpSet'
{ New-PveFirewallIpSet -Name 'testipset' -ErrorAction Stop } | { New-PveFirewallIpSet -Name 'testipset' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -179,7 +179,7 @@ Describe 'Remove-PveFirewallIpSet' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Remove-PveFirewallIpSet' Skip-IfMissing 'Remove-PveFirewallIpSet'
{ Remove-PveFirewallIpSet -Name 'testipset' -Confirm:$false -ErrorAction Stop } | { Remove-PveFirewallIpSet -Name 'testipset' -Confirm:$false -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -223,7 +223,7 @@ Describe 'Get-PveFirewallIpSetEntry' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Get-PveFirewallIpSetEntry' Skip-IfMissing 'Get-PveFirewallIpSetEntry'
{ Get-PveFirewallIpSetEntry -Name 'testipset' -ErrorAction Stop } | { Get-PveFirewallIpSetEntry -Name 'testipset' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -269,7 +269,7 @@ Describe 'New-PveFirewallIpSetEntry' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'New-PveFirewallIpSetEntry' Skip-IfMissing 'New-PveFirewallIpSetEntry'
{ New-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -ErrorAction Stop } | { New-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -315,7 +315,7 @@ Describe 'Set-PveFirewallIpSetEntry' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Set-PveFirewallIpSetEntry' Skip-IfMissing 'Set-PveFirewallIpSetEntry'
{ Set-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -ErrorAction Stop } | { Set-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -369,7 +369,7 @@ Describe 'Remove-PveFirewallIpSetEntry' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Remove-PveFirewallIpSetEntry' Skip-IfMissing 'Remove-PveFirewallIpSetEntry'
{ Remove-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -Confirm:$false -ErrorAction Stop } | { Remove-PveFirewallIpSetEntry -Name 'testipset' -Cidr '10.0.0.1' -Confirm:$false -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -168,7 +168,7 @@ Describe 'Get-PveFirewallRef' {
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Get-PveFirewallRef' Skip-IfMissing 'Get-PveFirewallRef'
{ Get-PveFirewallRef -ErrorAction Stop } | { Get-PveFirewallRef -Level Cluster -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -172,16 +172,16 @@ Describe 'Set-PveFirewallRule' {
$validateSet | Should -Not -BeNullOrEmpty $validateSet | Should -Not -BeNullOrEmpty
} }
It 'Should have Pos parameter' { It 'Should have Position parameter' {
Skip-IfMissing 'Set-PveFirewallRule' Skip-IfMissing 'Set-PveFirewallRule'
$script:Cmd.Parameters.ContainsKey('Pos') | Should -BeTrue $script:Cmd.Parameters.ContainsKey('Position') | Should -BeTrue
} }
} }
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Set-PveFirewallRule' Skip-IfMissing 'Set-PveFirewallRule'
{ Set-PveFirewallRule -Level 'cluster' -Pos 0 -ErrorAction Stop } | { Set-PveFirewallRule -Level 'cluster' -Position 0 -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }
@@ -227,16 +227,16 @@ Describe 'Remove-PveFirewallRule' {
$validateSet | Should -Not -BeNullOrEmpty $validateSet | Should -Not -BeNullOrEmpty
} }
It 'Should have Pos parameter' { It 'Should have Position parameter' {
Skip-IfMissing 'Remove-PveFirewallRule' Skip-IfMissing 'Remove-PveFirewallRule'
$script:Cmd.Parameters.ContainsKey('Pos') | Should -BeTrue $script:Cmd.Parameters.ContainsKey('Position') | Should -BeTrue
} }
} }
Context 'Without active session' { Context 'Without active session' {
It 'Should throw when no session is active' { It 'Should throw when no session is active' {
Skip-IfMissing 'Remove-PveFirewallRule' Skip-IfMissing 'Remove-PveFirewallRule'
{ Remove-PveFirewallRule -Level 'cluster' -Pos 0 -Confirm:$false -ErrorAction Stop } | { Remove-PveFirewallRule -Level 'cluster' -Position 0 -Confirm:$false -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*' Should -Throw '*No active Proxmox VE session*'
} }
} }