#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 " 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*' } } }