Files
Clint Branham f3b06171b2 fix: add -TimeoutSeconds for long-running HTTP calls
PveHttpClient was constructed without setting HttpClient.Timeout, so
.NET's 100s default applied to every request. Multi-GB ISO uploads via
Send-PveFile on a real LAN reliably tripped this with TaskCanceledException
after 100 seconds, and there was no way to override it.

- PveSession gains a Timeout (TimeSpan) property, defaulting to 100s.
- PveHttpClient accepts an optional per-instance timeout override that
  takes precedence over the session timeout.
- Connect-PveServer exposes -TimeoutSeconds to set the session default.
- Send-PveFile and Invoke-PveStorageDownload expose -TimeoutSeconds with
  a 30-minute implicit default so large uploads/downloads do not trip
  the 100s default. -TimeoutSeconds 0 means Timeout.InfiniteTimeSpan.

Tracked as F087. Closes #59.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 18:08:26 -05:00

181 lines
7.1 KiB
PowerShell

#Requires -Module Pester
<#
.SYNOPSIS
Pester 5 tests for Invoke-PveStorageDownload.
All tests are fully offline — no live Proxmox VE target is required.
If the cmdlet is not yet compiled the test is marked Skipped.
#>
BeforeAll {
. $PSScriptRoot/../_TestHelper.ps1
$script:CmdExists = $null -ne (Get-Command 'Invoke-PveStorageDownload' -ErrorAction SilentlyContinue)
function Skip-IfMissing([string]$Name) {
if (-not $script:CmdExists) {
Set-ItResult -Skipped -Because "$Name is not yet implemented in this build"
}
}
}
# ---------------------------------------------------------------------------
# Manifest contract
# ---------------------------------------------------------------------------
Describe 'Invoke-PveStorageDownload — manifest declaration' {
It 'Should be declared in CmdletsToExport' {
$manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1'
if (-not (Test-Path $manifestPath)) { Set-ItResult -Skipped -Because 'Manifest not found'; return }
$manifest = Import-PowerShellDataFile $manifestPath
$manifest.CmdletsToExport | Should -Contain 'Invoke-PveStorageDownload'
}
}
# ---------------------------------------------------------------------------
# Invoke-PveStorageDownload
# ---------------------------------------------------------------------------
Describe 'Invoke-PveStorageDownload' {
BeforeAll { $script:Cmd = Get-Command 'Invoke-PveStorageDownload' -ErrorAction SilentlyContinue }
Context 'Command existence' {
It 'Should be available after module import' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd | Should -Not -BeNullOrEmpty
}
It 'Should be a CmdletInfo (binary cmdlet)' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.CommandType | Should -Be 'Cmdlet'
}
}
Context 'ShouldProcess support' {
It 'Should support WhatIf' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
}
It 'Should support Confirm' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue
}
}
Context 'Required parameters' {
It 'Node should be Mandatory' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Node should be at Position 0' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$pos = $script:Cmd.Parameters['Node'].ParameterSets.Values |
ForEach-Object { $_.Position }
$pos | Should -Contain 0
}
It 'Storage should be Mandatory' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$isMandatory = $script:Cmd.Parameters['Storage'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Storage should be at Position 1' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$pos = $script:Cmd.Parameters['Storage'].ParameterSets.Values |
ForEach-Object { $_.Position }
$pos | Should -Contain 1
}
It 'Url should be Mandatory' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$isMandatory = $script:Cmd.Parameters['Url'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Url should be at Position 2' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$pos = $script:Cmd.Parameters['Url'].ParameterSets.Values |
ForEach-Object { $_.Position }
$pos | Should -Contain 2
}
It 'Filename should be Mandatory' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$isMandatory = $script:Cmd.Parameters['Filename'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Filename should be at Position 3' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$pos = $script:Cmd.Parameters['Filename'].ParameterSets.Values |
ForEach-Object { $_.Position }
$pos | Should -Contain 3
}
}
Context 'Optional parameters' {
It 'Should have ContentType parameter' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('ContentType') | Should -BeTrue
}
It 'ContentType should not be Mandatory' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$isMandatory = $script:Cmd.Parameters['ContentType'].ParameterSets.Values |
Where-Object { $_.IsMandatory }
$isMandatory | Should -BeNullOrEmpty
}
It 'ContentType should have a ValidateSet of iso, vztmpl, backup, import' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$validateSet = $script:Cmd.Parameters['ContentType'].Attributes |
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }
$validateSet | Should -Not -BeNullOrEmpty
$validValues = $validateSet.ValidValues
$validValues | Should -Contain 'iso'
$validValues | Should -Contain 'vztmpl'
$validValues | Should -Contain 'backup'
$validValues | Should -Contain 'import'
}
It 'Should have Wait switch parameter' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue
$script:Cmd.Parameters['Wait'].SwitchParameter | Should -BeTrue
}
It 'Should have TimeoutSeconds parameter' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('TimeoutSeconds') | Should -BeTrue
}
It 'TimeoutSeconds should reject negative values' {
Skip-IfMissing 'Invoke-PveStorageDownload'
{ Invoke-PveStorageDownload -Node 'pve1' -Storage 'local' -Url 'https://example.com/test.iso' -Filename 'test.iso' -TimeoutSeconds -1 -Confirm:$false -ErrorAction Stop } |
Should -Throw
}
}
Context 'Session parameter' {
It 'Should have Session parameter (inherited from PveCmdletBase)' {
Skip-IfMissing 'Invoke-PveStorageDownload'
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
}
}
Context 'Without active session' {
It 'Should throw when no session is active' {
Skip-IfMissing 'Invoke-PveStorageDownload'
{ Invoke-PveStorageDownload -Node 'pve1' -Storage 'local' -Url 'https://example.com/test.iso' -Filename 'test.iso' -Confirm:$false -ErrorAction Stop } |
Should -Throw '*No active Proxmox VE session*'
}
}
}