mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-18 09:03:14 +00:00
dc9b253195
Cmdlet fixes:
- GetPveSnapshotCmdlet: add -Name filter; fix s.SnapName → s.Name
- GetPveStorageCmdlet: add -Storage name filter
- GetPveNetworkCmdlet: add -Iface optional filter
- NewPveNetworkCmdlet: rename Interface → Iface (consistency with Set/Remove)
- SetPveNetworkCmdlet, RemovePveNetworkCmdlet: rename Interface → Iface
- RemovePveNetworkCmdlet, RemovePveSdnZoneCmdlet, RemovePveSdnVnetCmdlet,
RemovePveUserCmdlet: add ConfirmImpact = ConfirmImpact.High
- SetPveCloudInitConfigCmdlet: rename User → CiUser; move GetSession() first;
remove duplicate session variable
- SendPveIsoCmdlet: add sha512 to ChecksumAlgorithm ValidateSet
- GetPveUserCmdlet: add -Enabled switch; refactor into MatchesFilters(); fix
int? comparison (Enabled != 1)
- GetPvePermissionCmdlet: rename UgId → UserId
- SetPvePermissionCmdlet: rename RoleId → Role
- NewPveTemplateCmdlet: add ConfirmImpact.High; move GetSession() before
ShouldProcess so -WhatIf-less calls throw session error first
- NewPveVmFromTemplateCmdlet: rename Node → TemplateNode with [Alias("Node")]
- RemovePveSnapshotCmdlet, RestorePveSnapshotCmdlet: move GetSession() before
ShouldProcess so session check precedes confirm prompt
Test fixes:
- All 18 Pester test files: update DLL candidates to net9.0
- Fix foreach+It closure capture using -TestCases pattern
- Remove-PveVm, Remove-PveContainer no-session tests: add -Confirm:$false to
bypass ConfirmImpact.High prompt before GetSession() check
- Get-PveStorageContent test: add mandatory -Node/-Storage params
- Send-PveIso test: create temp file to satisfy FileExistsValidation
- New-PveVmFromTemplate test: add NewVmId to parameter splat
Tooling:
- Invoke-Tests.ps1: add -FromTerraform, explicit lab params, fix TFM
auto-detection via Select-Xml, fix Pester import, fix variable scoping
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
123 lines
4.8 KiB
PowerShell
123 lines
4.8 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.
|
|
$moduleRoot = Resolve-Path (Join-Path $PSScriptRoot '../../../src/PSProxmoxVE')
|
|
$dllCandidates = @(
|
|
Join-Path $moduleRoot 'bin/Debug/net9.0/PSProxmoxVE.dll'
|
|
Join-Path $moduleRoot 'bin/Release/net9.0/PSProxmoxVE.dll'
|
|
Join-Path $moduleRoot 'bin/Debug/net48/PSProxmoxVE.dll'
|
|
Join-Path $moduleRoot 'bin/Release/net48/PSProxmoxVE.dll'
|
|
)
|
|
|
|
$script:ModuleDll = $dllCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
|
|
|
|
if ($null -eq $script:ModuleDll) {
|
|
throw "PSProxmoxVE.dll not found. Build the project before running Pester tests."
|
|
}
|
|
|
|
Import-Module $script:ModuleDll -Force -ErrorAction Stop
|
|
}
|
|
|
|
Describe 'Connect-PveServer' {
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Get-Command 'Connect-PveServer' -ErrorAction SilentlyContinue |
|
|
Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should be a CmdletInfo (binary cmdlet)' {
|
|
(Get-Command 'Connect-PveServer').CommandType | Should -Be 'Cmdlet'
|
|
}
|
|
}
|
|
|
|
Context 'Parameter validation — missing required parameters' {
|
|
It 'Should throw when Server is omitted entirely' {
|
|
{ Connect-PveServer -ErrorAction Stop } | Should -Throw
|
|
}
|
|
|
|
It 'Should throw when Server is provided but neither Credential nor ApiToken is supplied' {
|
|
# Both parameter sets require one of Credential/ApiToken; omitting both is an error.
|
|
{ Connect-PveServer -Server 'pve.example.com' -ErrorAction Stop } | Should -Throw
|
|
}
|
|
}
|
|
|
|
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 have a Server parameter' {
|
|
$script:Cmd.Parameters.ContainsKey('Server') | Should -BeTrue
|
|
}
|
|
|
|
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 'Should have a Port parameter' {
|
|
$script:Cmd.Parameters.ContainsKey('Port') | Should -BeTrue
|
|
}
|
|
|
|
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 Credential parameter' {
|
|
$script:Cmd.Parameters.ContainsKey('Credential') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have an ApiToken parameter' {
|
|
$script:Cmd.Parameters.ContainsKey('ApiToken') | Should -BeTrue
|
|
}
|
|
|
|
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' {
|
|
$script:Cmd.Parameters.ContainsKey('PassThru') | Should -BeTrue
|
|
$script:Cmd.Parameters['PassThru'].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
|
|
}
|
|
}
|
|
}
|