mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-26 04:16:51 +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>
180 lines
7.9 KiB
PowerShell
180 lines
7.9 KiB
PowerShell
#Requires -Module Pester
|
|
<#
|
|
.SYNOPSIS
|
|
Pester 5 tests for Send-PveIso.
|
|
All tests are fully offline — no live Proxmox VE target is required.
|
|
If the cmdlet is not yet compiled the tests are marked Skipped.
|
|
#>
|
|
|
|
BeforeAll {
|
|
$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
|
|
|
|
$script:CmdExists = $null -ne (Get-Command 'Send-PveIso' -ErrorAction SilentlyContinue)
|
|
}
|
|
|
|
Describe 'Send-PveIso' {
|
|
|
|
Context 'Manifest declaration' {
|
|
It 'Should be declared in CmdletsToExport' {
|
|
$manifestPath = Join-Path $moduleRoot 'PSProxmoxVE.psd1'
|
|
if (-not (Test-Path $manifestPath)) { Set-ItResult -Skipped -Because 'Manifest not found'; return }
|
|
$manifest = Import-PowerShellDataFile $manifestPath
|
|
$manifest.CmdletsToExport | Should -Contain 'Send-PveIso'
|
|
}
|
|
}
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
(Get-Command 'Send-PveIso').CommandType | Should -Be 'Cmdlet'
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
BeforeAll {
|
|
$script:Cmd = Get-Command 'Send-PveIso' -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
It 'Should have Node parameter (Mandatory)' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should have Storage parameter (Mandatory)' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$isMandatory = $script:Cmd.Parameters['Storage'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should have Path parameter (Mandatory)' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$isMandatory = $script:Cmd.Parameters['Path'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should throw when Node is omitted' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
{ Send-PveIso -Storage 'local' -Path '/tmp/test.iso' -ErrorAction Stop } |
|
|
Should -Throw
|
|
}
|
|
|
|
It 'Should throw when Storage is omitted' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
{ Send-PveIso -Node 'pve-node1' -Path '/tmp/test.iso' -ErrorAction Stop } |
|
|
Should -Throw
|
|
}
|
|
|
|
It 'Should throw when Path is omitted' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
{ Send-PveIso -Node 'pve-node1' -Storage 'local' -ErrorAction Stop } |
|
|
Should -Throw
|
|
}
|
|
}
|
|
|
|
Context 'ChecksumAlgorithm ValidateSet' {
|
|
BeforeAll {
|
|
$script:Cmd = Get-Command 'Send-PveIso' -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
It 'Should have ChecksumAlgorithm parameter' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$script:Cmd.Parameters.ContainsKey('ChecksumAlgorithm') | Should -BeTrue
|
|
}
|
|
|
|
It 'ChecksumAlgorithm should have a ValidateSet attribute' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$validateSetAttr = $script:Cmd.Parameters['ChecksumAlgorithm'].Attributes |
|
|
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }
|
|
$validateSetAttr | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'ChecksumAlgorithm ValidateSet should include md5' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$validateSetAttr = $script:Cmd.Parameters['ChecksumAlgorithm'].Attributes |
|
|
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } |
|
|
Select-Object -First 1
|
|
$validateSetAttr.ValidValues | Should -Contain 'md5'
|
|
}
|
|
|
|
It 'ChecksumAlgorithm ValidateSet should include sha1' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$validateSetAttr = $script:Cmd.Parameters['ChecksumAlgorithm'].Attributes |
|
|
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } |
|
|
Select-Object -First 1
|
|
$validateSetAttr.ValidValues | Should -Contain 'sha1'
|
|
}
|
|
|
|
It 'ChecksumAlgorithm ValidateSet should include sha256' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$validateSetAttr = $script:Cmd.Parameters['ChecksumAlgorithm'].Attributes |
|
|
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } |
|
|
Select-Object -First 1
|
|
$validateSetAttr.ValidValues | Should -Contain 'sha256'
|
|
}
|
|
|
|
It 'ChecksumAlgorithm ValidateSet should include sha512' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$validateSetAttr = $script:Cmd.Parameters['ChecksumAlgorithm'].Attributes |
|
|
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } |
|
|
Select-Object -First 1
|
|
$validateSetAttr.ValidValues | Should -Contain 'sha512'
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess support' {
|
|
BeforeAll {
|
|
$script:Cmd = Get-Command 'Send-PveIso' -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
It 'Should support WhatIf' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Optional parameters' {
|
|
BeforeAll {
|
|
$script:Cmd = Get-Command 'Send-PveIso' -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
It 'Should have Checksum parameter' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$script:Cmd.Parameters.ContainsKey('Checksum') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have Session parameter' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Without active session' {
|
|
It 'Should throw when no session is active (without -WhatIf)' {
|
|
if (-not $script:CmdExists) { Set-ItResult -Skipped -Because 'Not yet compiled'; return }
|
|
$tmpIso = [System.IO.Path]::GetTempFileName()
|
|
try {
|
|
{ Send-PveIso -Node 'pve-node1' -Storage 'local' -Path $tmpIso -Confirm:$false -ErrorAction Stop } |
|
|
Should -Throw '*No active Proxmox VE session*'
|
|
} finally { Remove-Item $tmpIso -ErrorAction SilentlyContinue }
|
|
}
|
|
}
|
|
}
|