mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-09-04 03:05:32 +00:00
109dca657a
Skip-IfMissing skipped a test whenever the cmdlet under test was absent from the build, including the test asserting it exists. Every cmdlet compiles into one assembly, so there is no partial-build case for it to serve; all it did was hide a missing cmdlet. Delete the 37 copies and every call site, and drop the residual conditional skips in the same family (CmdExists probes, an attribute-presence skip in SdnCmdlets, a lifecycle helper skipping on a cmdlet-name collision fixed long ago). 894 It blocks only reflected [Cmdlet] and [Parameter] attributes back at the compiler: existence, CommandType -eq 'Cmdlet', Parameters.ContainsKey, IsMandatory reflection, and per-file CmdletsToExport asserts for whichever names an author remembered. Nothing reflected over the built assembly, so a new cmdlet missing from the manifest shipped invisible. One data-driven file replaces them: it diffs CmdletsToExport against the assembly's cmdlet types in both directions and asserts the conventions reflection can see. Behavioural tests are untouched: no-session errors, binding rejections, ShouldProcess and -WhatIf, ConfirmImpact, ValidateSet and ValidateRange values, parameter types, positions and pipeline binding. The generated help covered 169 of 194 cmdlets. Regenerated with the repo's own generate-help.ps1: 25 new markdown stubs, 13 existing docs picking up parameters added in earlier waves, and a rebuilt MAML. Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
120 lines
5.3 KiB
PowerShell
120 lines
5.3 KiB
PowerShell
#Requires -Module Pester
|
|
<#
|
|
.SYNOPSIS
|
|
Pester 5 tests for Disconnect-PveServer.
|
|
All tests are fully offline — no live Proxmox VE target is required.
|
|
#>
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/../_TestHelper.ps1
|
|
}
|
|
|
|
Describe 'Disconnect-PveServer' {
|
|
Context 'Parameter metadata' {
|
|
BeforeAll {
|
|
$script:Cmd = Get-Command 'Disconnect-PveServer'
|
|
}
|
|
|
|
It 'Should support ShouldProcess (have WhatIf and Confirm parameters)' {
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
$script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should declare ConfirmImpact Low (no explicit -Confirm needed for normal use)' {
|
|
# SupportsShouldProcess is reflected as WhatIf/Confirm parameters.
|
|
# ConfirmImpact=Low means PowerShell will not auto-prompt; just verify the
|
|
# attribute is present by confirming ShouldProcess support is enabled.
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Behaviour when no session is active' {
|
|
It 'Should run without error and emit a warning when no session exists' {
|
|
# Ensure module state has no active session by disconnecting first (may already be null).
|
|
# Disconnect-PveServer should emit a warning, not throw.
|
|
{ Disconnect-PveServer -ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
}
|
|
|
|
Context 'WhatIf support' {
|
|
It 'Should accept -WhatIf without throwing' {
|
|
{ Disconnect-PveServer -WhatIf -ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
}
|
|
|
|
Context 'Active session lifecycle' {
|
|
BeforeAll {
|
|
$script:PveSessionType = [PSProxmoxVE.Core.Authentication.PveSession]
|
|
$script:ModuleStateType = [System.AppDomain]::CurrentDomain.GetAssemblies() |
|
|
Where-Object { $_.GetName().Name -eq 'PSProxmoxVE' } |
|
|
ForEach-Object { $_.GetType('PSProxmoxVE.ModuleState') } |
|
|
Select-Object -First 1
|
|
$script:ModuleStateType | Should -Not -BeNullOrEmpty
|
|
|
|
$script:ActiveSessionProperty = $script:ModuleStateType.GetProperty(
|
|
'ActiveSession',
|
|
[System.Reflection.BindingFlags]'NonPublic, Static')
|
|
$script:ActiveSessionProperty | Should -Not -BeNullOrEmpty
|
|
|
|
$script:SessionCtor = $script:PveSessionType.GetConstructor(
|
|
[System.Reflection.BindingFlags]'NonPublic, Instance',
|
|
$null,
|
|
[type[]]@([string], [int], [bool], [string]),
|
|
$null)
|
|
$script:SessionCtor | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
AfterEach {
|
|
$script:ActiveSessionProperty.SetValue($null, $null)
|
|
}
|
|
|
|
It 'Should report "no session" when nothing is active' {
|
|
Disconnect-PveServer -Confirm:$false -WarningVariable w -WarningAction SilentlyContinue
|
|
$w[0] | Should -Match 'No active Proxmox VE session'
|
|
}
|
|
|
|
It 'Should clear the active session and warn on a second disconnect' {
|
|
$activeSession = $script:SessionCtor.Invoke(@('active.example', 8006, $false, 'activetoken'))
|
|
$script:ActiveSessionProperty.SetValue($null, $activeSession)
|
|
|
|
Disconnect-PveServer -Confirm:$false -WarningVariable w -WarningAction SilentlyContinue
|
|
$w | Should -BeNullOrEmpty
|
|
$script:ActiveSessionProperty.GetValue($null) | Should -BeNullOrEmpty
|
|
|
|
Disconnect-PveServer -Confirm:$false -WarningVariable w2 -WarningAction SilentlyContinue
|
|
$w2[0] | Should -Match 'No active Proxmox VE session'
|
|
}
|
|
|
|
It 'Should warn when disconnecting an explicit non-active session, and leave the active session untouched' {
|
|
$activeSession = $script:SessionCtor.Invoke(@('active.example', 8006, $false, 'activetoken'))
|
|
$script:ActiveSessionProperty.SetValue($null, $activeSession)
|
|
$mismatchedSession = $script:SessionCtor.Invoke(@('other.example', 8006, $false, 'othertoken'))
|
|
|
|
Disconnect-PveServer -Session $mismatchedSession -Confirm:$false -WarningVariable w -WarningAction SilentlyContinue
|
|
|
|
$w[0] | Should -Match 'not the module-level session'
|
|
$w[0] | Should -Match 'Remove-PveApiToken'
|
|
[object]::ReferenceEquals($script:ActiveSessionProperty.GetValue($null), $activeSession) | Should -BeTrue
|
|
}
|
|
|
|
It 'Should disconnect when -Session matches the active session' {
|
|
$activeSession = $script:SessionCtor.Invoke(@('active.example', 8006, $false, 'activetoken'))
|
|
$script:ActiveSessionProperty.SetValue($null, $activeSession)
|
|
|
|
Disconnect-PveServer -Session $activeSession -Confirm:$false -WarningVariable w -WarningAction SilentlyContinue
|
|
|
|
$w | Should -BeNullOrEmpty
|
|
$script:ActiveSessionProperty.GetValue($null) | Should -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should not clear the active session under -WhatIf' {
|
|
$activeSession = $script:SessionCtor.Invoke(@('active.example', 8006, $false, 'activetoken'))
|
|
$script:ActiveSessionProperty.SetValue($null, $activeSession)
|
|
|
|
Disconnect-PveServer -WhatIf -ErrorAction Stop
|
|
|
|
[object]::ReferenceEquals($script:ActiveSessionProperty.GetValue($null), $activeSession) | Should -BeTrue
|
|
}
|
|
}
|
|
}
|