Files
PSProxmoxVE/tests/PSProxmoxVE.Tests/Connection/Connect-PveServer.Tests.ps1
T
goodolclint-claude[bot] 109dca657a refactor: make the offline Pester suite able to fail (#153) (#205)
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>
2026-09-03 00:54:02 +00:00

97 lines
4.0 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for Connect-PveServer.
All tests are fully offline — no live Proxmox VE target is required.
The suite validates parameter metadata and parameter-set enforcement, which
are enforced by PowerShell itself and do not require a real HTTP call.
#>
BeforeAll {
# Resolve the built DLL relative to the repository root.
# Adjust the path if your build output directory differs.
. $PSScriptRoot/../_TestHelper.ps1
}
Describe 'Connect-PveServer' {
Context 'Parameter validation — required parameters' {
It 'Server should be Mandatory' {
$param = (Get-Command 'Connect-PveServer').Parameters['Server']
$isMandatory = $param.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Should require either Credential or ApiToken (both parameter sets exist)' {
$cmd = Get-Command 'Connect-PveServer'
$cmd.ParameterSets.Count | Should -BeGreaterOrEqual 2
}
}
Context 'Parameter validation — mutually exclusive parameter sets' {
It 'Should not allow both Credential and ApiToken together' {
$securePass = ConvertTo-SecureString 'hunter2' -AsPlainText -Force
$cred = [System.Management.Automation.PSCredential]::new('root@pam', $securePass)
{
Connect-PveServer `
-Server 'pve.example.com' `
-Credential $cred `
-ApiToken 'root@pam!mytoken=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' `
-ErrorAction Stop
} | Should -Throw
}
}
Context 'Parameter metadata' {
BeforeAll {
$script:Cmd = Get-Command 'Connect-PveServer'
}
It 'Should declare Server as Mandatory' {
$serverParam = $script:Cmd.Parameters['Server']
$isMandatory = $serverParam.ParameterSets.Values |
Where-Object { $_.IsMandatory } |
Select-Object -First 1
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Port should default to 8006' {
# Verify default via the static default-value metadata on the parameter.
$portParam = $script:Cmd.Parameters['Port']
$portParam | Should -Not -BeNullOrEmpty
}
It 'Should have a SkipCertificateCheck switch parameter' {
$script:Cmd.Parameters.ContainsKey('SkipCertificateCheck') | Should -BeTrue
$script:Cmd.Parameters['SkipCertificateCheck'].ParameterType |
Should -Be ([System.Management.Automation.SwitchParameter])
}
It 'Should have a PassThru switch parameter (deprecated, hidden)' {
$script:Cmd.Parameters.ContainsKey('PassThru') | Should -BeTrue
$script:Cmd.Parameters['PassThru'].ParameterType |
Should -Be ([System.Management.Automation.SwitchParameter])
}
It 'Should have a Quiet switch parameter' {
$script:Cmd.Parameters.ContainsKey('Quiet') | Should -BeTrue
$script:Cmd.Parameters['Quiet'].ParameterType |
Should -Be ([System.Management.Automation.SwitchParameter])
}
It 'Credential and ApiToken should belong to different parameter sets' {
$credSets = $script:Cmd.Parameters['Credential'].ParameterSets.Keys
$tokenSets = $script:Cmd.Parameters['ApiToken'].ParameterSets.Keys
$overlap = $credSets | Where-Object { $tokenSets -contains $_ }
$overlap | Should -BeNullOrEmpty
}
It 'TimeoutSeconds should reject negative values' {
$securePass = ConvertTo-SecureString 'hunter2' -AsPlainText -Force
$cred = [System.Management.Automation.PSCredential]::new('root@pam', $securePass)
{
Connect-PveServer -Server 'pve.example.com' -Credential $cred -TimeoutSeconds -1 -ErrorAction Stop
} | Should -Throw
}
}
}