diff --git a/tests/PSProxmoxVE.Tests/Containers/ContainerConfigCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Containers/ContainerConfigCmdlets.Tests.ps1 new file mode 100644 index 0000000..e78f4f9 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Containers/ContainerConfigCmdlets.Tests.ps1 @@ -0,0 +1,363 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for container configuration cmdlets: + Copy-PveContainer, Get-PveContainerConfig, Set-PveContainerConfig. + + All tests are fully offline — no live Proxmox VE target is required. + If a cmdlet is not yet compiled the test is marked Skipped. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 + + $script:Availability = @{} + foreach ($name in @('Copy-PveContainer', 'Get-PveContainerConfig', 'Set-PveContainerConfig')) { + $script:Availability[$name] = $null -ne (Get-Command $name -ErrorAction SilentlyContinue) + } + + function Skip-IfMissing([string]$Name) { + if (-not $script:Availability[$Name]) { + Set-ItResult -Skipped -Because "$Name is not yet implemented in this build" + } + } +} + +# --------------------------------------------------------------------------- +# Manifest contract +# --------------------------------------------------------------------------- +Describe 'Container config cmdlets — manifest declarations' { + BeforeAll { + $manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1' + $script:Manifest = if (Test-Path $manifestPath) { Import-PowerShellDataFile $manifestPath } else { $null } + } + + It " should be declared in CmdletsToExport" -TestCases @( + @{ cmdName = 'Copy-PveContainer' } + @{ cmdName = 'Get-PveContainerConfig' } + @{ cmdName = 'Set-PveContainerConfig' } + ) { + if ($null -eq $script:Manifest) { Set-ItResult -Skipped -Because 'Manifest not found'; return } + $script:Manifest.CmdletsToExport | Should -Contain $cmdName + } +} + +# --------------------------------------------------------------------------- +# Copy-PveContainer +# --------------------------------------------------------------------------- +Describe 'Copy-PveContainer' { + + BeforeAll { $script:Cmd = Get-Command 'Copy-PveContainer' -ErrorAction SilentlyContinue } + + Context 'Command existence' { + It 'Should be available after module import' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd | Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.CommandType | Should -Be 'Cmdlet' + } + } + + Context 'ShouldProcess support' { + It 'Should support WhatIf' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + } + + Context 'Required parameters' { + It 'SourceNode should be Mandatory' { + Skip-IfMissing 'Copy-PveContainer' + $isMandatory = $script:Cmd.Parameters['SourceNode'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be Mandatory' { + Skip-IfMissing 'Copy-PveContainer' + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + } + + Context 'Optional parameters' { + It 'Should have NewVmId parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('NewVmId') | Should -BeTrue + } + + It 'NewVmId should not be Mandatory' { + Skip-IfMissing 'Copy-PveContainer' + $isMandatory = $script:Cmd.Parameters['NewVmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have NewName parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('NewName') | Should -BeTrue + } + + It 'Should have TargetNode parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('TargetNode') | Should -BeTrue + } + + It 'Should have Full switch parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('Full') | Should -BeTrue + $script:Cmd.Parameters['Full'].SwitchParameter | Should -BeTrue + } + + It 'Should have Storage parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('Storage') | Should -BeTrue + } + + It 'Should have Wait switch parameter' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue + $script:Cmd.Parameters['Wait'].SwitchParameter | Should -BeTrue + } + } + + Context 'Pipeline support' { + It 'VmId should accept pipeline input by property name' { + Skip-IfMissing 'Copy-PveContainer' + $vmid = $script:Cmd.Parameters['VmId'] + $acceptsByPropName = $vmid.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + } + + Context 'Session parameter' { + It 'Should have Session parameter (inherited from PveCmdletBase)' { + Skip-IfMissing 'Copy-PveContainer' + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'Without active session' { + It 'Should throw when no session is active' { + Skip-IfMissing 'Copy-PveContainer' + { Copy-PveContainer -SourceNode 'pve1' -VmId 100 -Confirm:$false -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + } +} + +# --------------------------------------------------------------------------- +# Get-PveContainerConfig +# --------------------------------------------------------------------------- +Describe 'Get-PveContainerConfig' { + + BeforeAll { $script:Cmd = Get-Command 'Get-PveContainerConfig' -ErrorAction SilentlyContinue } + + Context 'Command existence' { + It 'Should be available after module import' { + Skip-IfMissing 'Get-PveContainerConfig' + $script:Cmd | Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + Skip-IfMissing 'Get-PveContainerConfig' + $script:Cmd.CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Required parameters' { + It 'Node should be Mandatory' { + Skip-IfMissing 'Get-PveContainerConfig' + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be Mandatory' { + Skip-IfMissing 'Get-PveContainerConfig' + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + } + + Context 'Pipeline support' { + It 'Node should accept pipeline input by property name' { + Skip-IfMissing 'Get-PveContainerConfig' + $node = $script:Cmd.Parameters['Node'] + $acceptsByPropName = $node.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'VmId should accept pipeline input by property name' { + Skip-IfMissing 'Get-PveContainerConfig' + $vmid = $script:Cmd.Parameters['VmId'] + $acceptsByPropName = $vmid.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + } + + Context 'Session parameter' { + It 'Should have Session parameter (inherited from PveCmdletBase)' { + Skip-IfMissing 'Get-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'ShouldProcess not required' { + It 'Should not have WhatIf (Get verb is read-only)' { + Skip-IfMissing 'Get-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeFalse + } + } + + Context 'Without active session' { + It 'Should throw when no session is active' { + Skip-IfMissing 'Get-PveContainerConfig' + { Get-PveContainerConfig -Node 'pve1' -VmId 100 -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + } +} + +# --------------------------------------------------------------------------- +# Set-PveContainerConfig +# --------------------------------------------------------------------------- +Describe 'Set-PveContainerConfig' { + + BeforeAll { $script:Cmd = Get-Command 'Set-PveContainerConfig' -ErrorAction SilentlyContinue } + + Context 'Command existence' { + It 'Should be available after module import' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd | Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.CommandType | Should -Be 'Cmdlet' + } + } + + Context 'ShouldProcess support' { + It 'Should support WhatIf' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + } + + Context 'Required parameters' { + It 'Node should be Mandatory' { + Skip-IfMissing 'Set-PveContainerConfig' + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be Mandatory' { + Skip-IfMissing 'Set-PveContainerConfig' + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + } + + Context 'Optional configuration parameters' { + It 'Should have Hostname parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Hostname') | Should -BeTrue + } + + It 'Hostname should not be Mandatory' { + Skip-IfMissing 'Set-PveContainerConfig' + $isMandatory = $script:Cmd.Parameters['Hostname'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have Cores parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Cores') | Should -BeTrue + } + + It 'Should have Memory parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Memory') | Should -BeTrue + } + + It 'Should have Swap parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Swap') | Should -BeTrue + } + + It 'Should have Description parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Description') | Should -BeTrue + } + + It 'Should have Tags parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Tags') | Should -BeTrue + } + + It 'Should have Nameserver parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Nameserver') | Should -BeTrue + } + + It 'Should have SearchDomain parameter' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('SearchDomain') | Should -BeTrue + } + } + + Context 'Pipeline support' { + It 'Node should accept pipeline input by property name' { + Skip-IfMissing 'Set-PveContainerConfig' + $node = $script:Cmd.Parameters['Node'] + $acceptsByPropName = $node.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'VmId should accept pipeline input by property name' { + Skip-IfMissing 'Set-PveContainerConfig' + $vmid = $script:Cmd.Parameters['VmId'] + $acceptsByPropName = $vmid.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + } + + Context 'Session parameter' { + It 'Should have Session parameter (inherited from PveCmdletBase)' { + Skip-IfMissing 'Set-PveContainerConfig' + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'Without active session' { + It 'Should throw when no session is active' { + Skip-IfMissing 'Set-PveContainerConfig' + { Set-PveContainerConfig -Node 'pve1' -VmId 100 -Hostname 'test' -Confirm:$false -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Nodes/NodeCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Nodes/NodeCmdlets.Tests.ps1 new file mode 100644 index 0000000..1ca0486 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Nodes/NodeCmdlets.Tests.ps1 @@ -0,0 +1,170 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for Get-PveNode and Get-PveNodeStatus. + All tests are fully offline — no live Proxmox VE target is required. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 +} + +# --------------------------------------------------------------------------- +# Get-PveNode +# --------------------------------------------------------------------------- +Describe 'Get-PveNode' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Get-PveNode' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Get-PveNode').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter validation' { + BeforeAll { + $script:Cmd = Get-Command 'Get-PveNode' + } + + It 'Should have Name parameter' { + $script:Cmd.Parameters.ContainsKey('Name') | Should -BeTrue + } + + It 'Name should not be Mandatory' { + $p = $script:Cmd.Parameters['Name'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Name should be at Position 0' { + $p = $script:Cmd.Parameters['Name'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + + It 'Name should be of type String' { + $script:Cmd.Parameters['Name'].ParameterType | Should -Be ([string]) + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + + It 'Session should not be Mandatory' { + $p = $script:Cmd.Parameters['Session'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should declare PveNode as OutputType' { + $outputTypes = $script:Cmd.OutputType.Type + $outputTypes.Name | Should -Contain 'PveNode' + } + } + + Context 'Without active session' { + It 'Should throw when no session is active and no -Session is supplied' { + { Get-PveNode -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Get-PveNode -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +} + +# --------------------------------------------------------------------------- +# Get-PveNodeStatus +# --------------------------------------------------------------------------- +Describe 'Get-PveNodeStatus' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Get-PveNodeStatus' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Get-PveNodeStatus').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter validation' { + BeforeAll { + $script:Cmd = Get-Command 'Get-PveNodeStatus' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $p = $script:Cmd.Parameters['Node'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be at Position 0' { + $p = $script:Cmd.Parameters['Node'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Node should accept pipeline input by property name' { + $p = $script:Cmd.Parameters['Node'] + $acceptsByPropName = $p.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + + It 'Session should not be Mandatory' { + $p = $script:Cmd.Parameters['Session'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should declare PveNodeStatus as OutputType' { + $outputTypes = $script:Cmd.OutputType.Type + $outputTypes.Name | Should -Contain 'PveNodeStatus' + } + } + + Context 'Without active session' { + It 'Should throw when no session is active and no -Session is supplied' { + { Get-PveNodeStatus -Node 'pve1' -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Get-PveNodeStatus -Node 'pve1' -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + + It 'Should require the Node parameter' { + { Get-PveNodeStatus -ErrorAction Stop } | + Should -Throw '*Node*' + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Storage/StorageDownload.Tests.ps1 b/tests/PSProxmoxVE.Tests/Storage/StorageDownload.Tests.ps1 new file mode 100644 index 0000000..1a49b2a --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Storage/StorageDownload.Tests.ps1 @@ -0,0 +1,169 @@ +#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 + } + } + + 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*' + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Tasks/TaskCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Tasks/TaskCmdlets.Tests.ps1 new file mode 100644 index 0000000..710d5f6 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Tasks/TaskCmdlets.Tests.ps1 @@ -0,0 +1,287 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for Get-PveTask and Wait-PveTask. + All tests are fully offline — no live Proxmox VE target is required. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 +} + +# --------------------------------------------------------------------------- +# Get-PveTask +# --------------------------------------------------------------------------- +Describe 'Get-PveTask' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Get-PveTask' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Get-PveTask').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter validation' { + BeforeAll { + $script:Cmd = Get-Command 'Get-PveTask' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $p = $script:Cmd.Parameters['Node'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be at Position 0' { + $p = $script:Cmd.Parameters['Node'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Should have Upid parameter' { + $script:Cmd.Parameters.ContainsKey('Upid') | Should -BeTrue + } + + It 'Upid should be Mandatory' { + $p = $script:Cmd.Parameters['Upid'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Upid should be at Position 1' { + $p = $script:Cmd.Parameters['Upid'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 1 + } + + It 'Upid should be of type String' { + $script:Cmd.Parameters['Upid'].ParameterType | Should -Be ([string]) + } + + It 'Upid should accept pipeline input by property name' { + $p = $script:Cmd.Parameters['Upid'] + $acceptsByPropName = $p.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + + It 'Session should not be Mandatory' { + $p = $script:Cmd.Parameters['Session'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should declare PveTask as OutputType' { + $outputTypes = $script:Cmd.OutputType.Type + $outputTypes.Name | Should -Contain 'PveTask' + } + + It 'Both Node and Upid should be required together' { + $mandatoryParams = @('Node', 'Upid') + foreach ($paramName in $mandatoryParams) { + $p = $script:Cmd.Parameters[$paramName] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty -Because "$paramName should be mandatory" + } + } + } + + Context 'Without active session' { + It 'Should throw when no session is active and no -Session is supplied' { + { Get-PveTask -Node 'pve1' -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Get-PveTask -Node 'pve1' -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + + It 'Should require the Node parameter' { + { Get-PveTask -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop } | + Should -Throw '*Node*' + } + + It 'Should require the Upid parameter' { + { Get-PveTask -Node 'pve1' -ErrorAction Stop } | + Should -Throw '*Upid*' + } + } +} + +# --------------------------------------------------------------------------- +# Wait-PveTask +# --------------------------------------------------------------------------- +Describe 'Wait-PveTask' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Wait-PveTask' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Wait-PveTask').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter validation' { + BeforeAll { + $script:Cmd = Get-Command 'Wait-PveTask' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $p = $script:Cmd.Parameters['Node'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be at Position 0' { + $p = $script:Cmd.Parameters['Node'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Should have Upid parameter' { + $script:Cmd.Parameters.ContainsKey('Upid') | Should -BeTrue + } + + It 'Upid should be Mandatory' { + $p = $script:Cmd.Parameters['Upid'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Upid should be at Position 1' { + $p = $script:Cmd.Parameters['Upid'] + $pos = $p.ParameterSets.Values | ForEach-Object { $_.Position } + $pos | Should -Contain 1 + } + + It 'Upid should be of type String' { + $script:Cmd.Parameters['Upid'].ParameterType | Should -Be ([string]) + } + + It 'Upid should accept pipeline input by property name' { + $p = $script:Cmd.Parameters['Upid'] + $acceptsByPropName = $p.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have Timeout parameter' { + $script:Cmd.Parameters.ContainsKey('Timeout') | Should -BeTrue + } + + It 'Timeout should not be Mandatory' { + $p = $script:Cmd.Parameters['Timeout'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Timeout should be of type Nullable[TimeSpan]' { + $script:Cmd.Parameters['Timeout'].ParameterType | + Should -Be ([System.Nullable[System.TimeSpan]]) + } + + It 'Should have PollInterval parameter' { + $script:Cmd.Parameters.ContainsKey('PollInterval') | Should -BeTrue + } + + It 'PollInterval should not be Mandatory' { + $p = $script:Cmd.Parameters['PollInterval'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'PollInterval should be of type Nullable[TimeSpan]' { + $script:Cmd.Parameters['PollInterval'].ParameterType | + Should -Be ([System.Nullable[System.TimeSpan]]) + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + + It 'Session should not be Mandatory' { + $p = $script:Cmd.Parameters['Session'] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should declare PveTask as OutputType' { + $outputTypes = $script:Cmd.OutputType.Type + $outputTypes.Name | Should -Contain 'PveTask' + } + + It 'Both Node and Upid should be required, Timeout and PollInterval optional' { + $mandatoryParams = @('Node', 'Upid') + foreach ($paramName in $mandatoryParams) { + $p = $script:Cmd.Parameters[$paramName] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty -Because "$paramName should be mandatory" + } + + $optionalParams = @('Timeout', 'PollInterval', 'Session') + foreach ($paramName in $optionalParams) { + $p = $script:Cmd.Parameters[$paramName] + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty -Because "$paramName should be optional" + } + } + } + + Context 'Without active session' { + It 'Should throw when no session is active and no -Session is supplied' { + { Wait-PveTask -Node 'pve1' -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Wait-PveTask -Node 'pve1' -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + + It 'Should require the Node parameter' { + { Wait-PveTask -Upid 'UPID:pve1:00001234:0A1B2C3D:12345678:qmcreate:100:user@pam:' -ErrorAction Stop } | + Should -Throw '*Node*' + } + + It 'Should require the Upid parameter' { + { Wait-PveTask -Node 'pve1' -ErrorAction Stop } | + Should -Throw '*Upid*' + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Users/RoleCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Users/RoleCmdlets.Tests.ps1 new file mode 100644 index 0000000..2242a44 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Users/RoleCmdlets.Tests.ps1 @@ -0,0 +1,199 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for role cmdlets: + New-PveRole, Remove-PveRole. + + All tests are fully offline — no live Proxmox VE target is required. + If a cmdlet is not yet compiled the test is marked Skipped. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 + + $script:Availability = @{} + foreach ($name in @('New-PveRole', 'Remove-PveRole')) { + $script:Availability[$name] = $null -ne (Get-Command $name -ErrorAction SilentlyContinue) + } + + function Skip-IfMissing([string]$Name) { + if (-not $script:Availability[$Name]) { + Set-ItResult -Skipped -Because "$Name is not yet implemented in this build" + } + } +} + +# --------------------------------------------------------------------------- +# Manifest contract +# --------------------------------------------------------------------------- +Describe 'Role cmdlets — manifest declarations' { + BeforeAll { + $manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1' + $script:Manifest = if (Test-Path $manifestPath) { Import-PowerShellDataFile $manifestPath } else { $null } + } + + It " should be declared in CmdletsToExport" -TestCases @( + @{ cmdName = 'New-PveRole' } + @{ cmdName = 'Remove-PveRole' } + ) { + if ($null -eq $script:Manifest) { Set-ItResult -Skipped -Because 'Manifest not found'; return } + $script:Manifest.CmdletsToExport | Should -Contain $cmdName + } +} + +# --------------------------------------------------------------------------- +# New-PveRole +# --------------------------------------------------------------------------- +Describe 'New-PveRole' { + + BeforeAll { $script:Cmd = Get-Command 'New-PveRole' -ErrorAction SilentlyContinue } + + Context 'Command existence' { + It 'Should be available after module import' { + Skip-IfMissing 'New-PveRole' + $script:Cmd | Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + Skip-IfMissing 'New-PveRole' + $script:Cmd.CommandType | Should -Be 'Cmdlet' + } + } + + Context 'ShouldProcess support' { + It 'Should support WhatIf' { + Skip-IfMissing 'New-PveRole' + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm' { + Skip-IfMissing 'New-PveRole' + $script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + } + + Context 'Required parameters' { + It 'RoleId should be Mandatory' { + Skip-IfMissing 'New-PveRole' + $isMandatory = $script:Cmd.Parameters['RoleId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'RoleId should be at Position 0' { + Skip-IfMissing 'New-PveRole' + $pos = $script:Cmd.Parameters['RoleId'].ParameterSets.Values | + ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + } + + Context 'Optional parameters' { + It 'Should have Privileges parameter' { + Skip-IfMissing 'New-PveRole' + $script:Cmd.Parameters.ContainsKey('Privileges') | Should -BeTrue + } + + It 'Privileges should not be Mandatory' { + Skip-IfMissing 'New-PveRole' + $isMandatory = $script:Cmd.Parameters['Privileges'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Privileges should be at Position 1' { + Skip-IfMissing 'New-PveRole' + $pos = $script:Cmd.Parameters['Privileges'].ParameterSets.Values | + ForEach-Object { $_.Position } + $pos | Should -Contain 1 + } + } + + Context 'Session parameter' { + It 'Should have Session parameter (inherited from PveCmdletBase)' { + Skip-IfMissing 'New-PveRole' + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'Without active session' { + It 'Should throw when no session is active' { + Skip-IfMissing 'New-PveRole' + { New-PveRole -RoleId 'TestRole' -Confirm:$false -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + } +} + +# --------------------------------------------------------------------------- +# Remove-PveRole +# --------------------------------------------------------------------------- +Describe 'Remove-PveRole' { + + BeforeAll { $script:Cmd = Get-Command 'Remove-PveRole' -ErrorAction SilentlyContinue } + + Context 'Command existence' { + It 'Should be available after module import' { + Skip-IfMissing 'Remove-PveRole' + $script:Cmd | Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + Skip-IfMissing 'Remove-PveRole' + $script:Cmd.CommandType | Should -Be 'Cmdlet' + } + } + + Context 'ShouldProcess support' { + It 'Should support WhatIf' { + Skip-IfMissing 'Remove-PveRole' + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm' { + Skip-IfMissing 'Remove-PveRole' + $script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + } + + Context 'Required parameters' { + It 'RoleId should be Mandatory' { + Skip-IfMissing 'Remove-PveRole' + $isMandatory = $script:Cmd.Parameters['RoleId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'RoleId should be at Position 0' { + Skip-IfMissing 'Remove-PveRole' + $pos = $script:Cmd.Parameters['RoleId'].ParameterSets.Values | + ForEach-Object { $_.Position } + $pos | Should -Contain 0 + } + } + + Context 'Pipeline support' { + It 'RoleId should accept pipeline input by property name' { + Skip-IfMissing 'Remove-PveRole' + $roleId = $script:Cmd.Parameters['RoleId'] + $acceptsByPropName = $roleId.ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + } + + Context 'Session parameter' { + It 'Should have Session parameter (inherited from PveCmdletBase)' { + Skip-IfMissing 'Remove-PveRole' + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'Without active session' { + It 'Should throw when no session is active' { + Skip-IfMissing 'Remove-PveRole' + { Remove-PveRole -RoleId 'TestRole' -Confirm:$false -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Vms/VmAdvancedOps.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/VmAdvancedOps.Tests.ps1 new file mode 100644 index 0000000..8ae83c0 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Vms/VmAdvancedOps.Tests.ps1 @@ -0,0 +1,350 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for VM advanced operation cmdlets: + Copy-PveVm, Move-PveVm. + + All tests are fully offline — no live Proxmox VE target is required. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 +} + +# --------------------------------------------------------------------------- +# Copy-PveVm +# --------------------------------------------------------------------------- +Describe 'Copy-PveVm' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Copy-PveVm' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Copy-PveVm').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter metadata' { + BeforeAll { + $script:Cmd = Get-Command 'Copy-PveVm' + } + + # --- SourceNode --- + It 'Should have SourceNode parameter' { + $script:Cmd.Parameters.ContainsKey('SourceNode') | Should -BeTrue + } + + It 'SourceNode should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['SourceNode'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'SourceNode should be of type String' { + $script:Cmd.Parameters['SourceNode'].ParameterType | Should -Be ([string]) + } + + # --- VmId --- + It 'Should have VmId parameter' { + $script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue + } + + It 'VmId should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be of type Int32' { + $script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int]) + } + + It 'VmId should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + # --- NewVmId (optional) --- + It 'Should have NewVmId parameter' { + $script:Cmd.Parameters.ContainsKey('NewVmId') | Should -BeTrue + } + + It 'NewVmId should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['NewVmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'NewVmId should be of nullable Int32 type' { + $script:Cmd.Parameters['NewVmId'].ParameterType | + Should -Be ([System.Nullable[int]]) + } + + # --- NewName (optional) --- + It 'Should have NewName parameter' { + $script:Cmd.Parameters.ContainsKey('NewName') | Should -BeTrue + } + + It 'NewName should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['NewName'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'NewName should be of type String' { + $script:Cmd.Parameters['NewName'].ParameterType | Should -Be ([string]) + } + + # --- TargetNode (optional) --- + It 'Should have TargetNode parameter' { + $script:Cmd.Parameters.ContainsKey('TargetNode') | Should -BeTrue + } + + It 'TargetNode should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['TargetNode'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'TargetNode should be of type String' { + $script:Cmd.Parameters['TargetNode'].ParameterType | Should -Be ([string]) + } + + # --- Full (switch, optional) --- + It 'Should have Full switch parameter' { + $script:Cmd.Parameters.ContainsKey('Full') | Should -BeTrue + $script:Cmd.Parameters['Full'].ParameterType | + Should -Be ([System.Management.Automation.SwitchParameter]) + } + + It 'Full should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Full'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + # --- Storage (optional) --- + It 'Should have Storage parameter' { + $script:Cmd.Parameters.ContainsKey('Storage') | Should -BeTrue + } + + It 'Storage should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Storage'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Storage should be of type String' { + $script:Cmd.Parameters['Storage'].ParameterType | Should -Be ([string]) + } + + # --- Wait (switch, optional) --- + It 'Should have Wait switch parameter' { + $script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue + $script:Cmd.Parameters['Wait'].ParameterType | + Should -Be ([System.Management.Automation.SwitchParameter]) + } + + It 'Wait should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Wait'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + # --- Session (inherited) --- + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'ShouldProcess support' { + It 'Should support ShouldProcess (WhatIf parameter exists)' { + $cmd = Get-Command 'Copy-PveVm' + $cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm parameter' { + $cmd = Get-Command 'Copy-PveVm' + $cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + + It 'Should not throw with -WhatIf (no session required)' { + { Copy-PveVm -SourceNode 'pve-node1' -VmId 100 -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + + It 'Should not throw with -WhatIf and optional params' { + { Copy-PveVm -SourceNode 'pve-node1' -VmId 100 -NewVmId 200 -NewName 'clone-test' -TargetNode 'pve-node2' -Full -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + } + + Context 'Without active session' { + It 'Should throw when no session is active (without -WhatIf)' { + { Copy-PveVm -SourceNode 'pve-node1' -VmId 100 -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Copy-PveVm -SourceNode 'pve-node1' -VmId 100 -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +} + +# --------------------------------------------------------------------------- +# Move-PveVm +# --------------------------------------------------------------------------- +Describe 'Move-PveVm' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Move-PveVm' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Move-PveVm').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter metadata' { + BeforeAll { + $script:Cmd = Get-Command 'Move-PveVm' + } + + # --- Node --- + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Node should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + # --- VmId --- + It 'Should have VmId parameter' { + $script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue + } + + It 'VmId should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be of type Int32' { + $script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int]) + } + + It 'VmId should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + # --- TargetNode --- + It 'Should have TargetNode parameter' { + $script:Cmd.Parameters.ContainsKey('TargetNode') | Should -BeTrue + } + + It 'TargetNode should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['TargetNode'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'TargetNode should be of type String' { + $script:Cmd.Parameters['TargetNode'].ParameterType | Should -Be ([string]) + } + + # --- Online (switch, optional) --- + It 'Should have Online switch parameter' { + $script:Cmd.Parameters.ContainsKey('Online') | Should -BeTrue + $script:Cmd.Parameters['Online'].ParameterType | + Should -Be ([System.Management.Automation.SwitchParameter]) + } + + It 'Online should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Online'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + # --- Wait (switch, optional) --- + It 'Should have Wait switch parameter' { + $script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue + $script:Cmd.Parameters['Wait'].ParameterType | + Should -Be ([System.Management.Automation.SwitchParameter]) + } + + It 'Wait should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Wait'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + # --- Session (inherited) --- + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'ShouldProcess support' { + It 'Should support ShouldProcess (WhatIf parameter exists)' { + $cmd = Get-Command 'Move-PveVm' + $cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm parameter' { + $cmd = Get-Command 'Move-PveVm' + $cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + + It 'Should not throw with -WhatIf (no session required)' { + { Move-PveVm -Node 'pve-node1' -VmId 100 -TargetNode 'pve-node2' -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + + It 'Should not throw with -WhatIf and -Online flag' { + { Move-PveVm -Node 'pve-node1' -VmId 100 -TargetNode 'pve-node2' -Online -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + } + + Context 'Without active session' { + It 'Should throw when no session is active (without -WhatIf)' { + { Move-PveVm -Node 'pve-node1' -VmId 100 -TargetNode 'pve-node2' -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Move-PveVm -Node 'pve-node1' -VmId 100 -TargetNode 'pve-node2' -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +} diff --git a/tests/PSProxmoxVE.Tests/Vms/VmConfigCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/VmConfigCmdlets.Tests.ps1 new file mode 100644 index 0000000..a8a2937 --- /dev/null +++ b/tests/PSProxmoxVE.Tests/Vms/VmConfigCmdlets.Tests.ps1 @@ -0,0 +1,397 @@ +#Requires -Module Pester +<# +.SYNOPSIS + Pester 5 tests for VM configuration cmdlets: + Get-PveVmConfig, Set-PveVmConfig, Resize-PveVmDisk. + + All tests are fully offline — no live Proxmox VE target is required. +#> + +BeforeAll { + . $PSScriptRoot/../_TestHelper.ps1 +} + +# --------------------------------------------------------------------------- +# Get-PveVmConfig +# --------------------------------------------------------------------------- +Describe 'Get-PveVmConfig' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Get-PveVmConfig' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Get-PveVmConfig').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter metadata' { + BeforeAll { + $script:Cmd = Get-Command 'Get-PveVmConfig' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Node should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have VmId parameter' { + $script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue + } + + It 'VmId should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be of type Int32' { + $script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int]) + } + + It 'VmId should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + + It 'Should not support ShouldProcess (read-only cmdlet)' { + $script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeFalse + } + } + + Context 'Without active session' { + It 'Should throw when no session is active and no -Session is supplied' { + { Get-PveVmConfig -Node 'pve-node1' -VmId 100 -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Get-PveVmConfig -Node 'pve-node1' -VmId 100 -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +} + +# --------------------------------------------------------------------------- +# Set-PveVmConfig +# --------------------------------------------------------------------------- +Describe 'Set-PveVmConfig' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Set-PveVmConfig' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Set-PveVmConfig').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter metadata' { + BeforeAll { + $script:Cmd = Get-Command 'Set-PveVmConfig' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have VmId parameter' { + $script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue + } + + It 'VmId should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + # Configuration parameters — all optional + It 'Should have Cores parameter (optional, Int32)' { + $script:Cmd.Parameters.ContainsKey('Cores') | Should -BeTrue + $script:Cmd.Parameters['Cores'].ParameterType | + Should -Be ([System.Nullable[int]]) + $isMandatory = $script:Cmd.Parameters['Cores'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have Sockets parameter (optional, Int32)' { + $script:Cmd.Parameters.ContainsKey('Sockets') | Should -BeTrue + $script:Cmd.Parameters['Sockets'].ParameterType | + Should -Be ([System.Nullable[int]]) + $isMandatory = $script:Cmd.Parameters['Sockets'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have Memory parameter (optional, Int32)' { + $script:Cmd.Parameters.ContainsKey('Memory') | Should -BeTrue + $script:Cmd.Parameters['Memory'].ParameterType | + Should -Be ([System.Nullable[int]]) + $isMandatory = $script:Cmd.Parameters['Memory'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have CpuType parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('CpuType') | Should -BeTrue + $script:Cmd.Parameters['CpuType'].ParameterType | Should -Be ([string]) + $isMandatory = $script:Cmd.Parameters['CpuType'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have Description parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('Description') | Should -BeTrue + $script:Cmd.Parameters['Description'].ParameterType | Should -Be ([string]) + } + + It 'Should have Tags parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('Tags') | Should -BeTrue + $script:Cmd.Parameters['Tags'].ParameterType | Should -Be ([string]) + } + + It 'Should have Bios parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('Bios') | Should -BeTrue + $script:Cmd.Parameters['Bios'].ParameterType | Should -Be ([string]) + } + + It 'Should have Machine parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('Machine') | Should -BeTrue + $script:Cmd.Parameters['Machine'].ParameterType | Should -Be ([string]) + } + + It 'Should have OsType parameter (optional, String)' { + $script:Cmd.Parameters.ContainsKey('OsType') | Should -BeTrue + $script:Cmd.Parameters['OsType'].ParameterType | Should -Be ([string]) + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'ShouldProcess support' { + It 'Should support ShouldProcess (WhatIf parameter exists)' { + $cmd = Get-Command 'Set-PveVmConfig' + $cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm parameter' { + $cmd = Get-Command 'Set-PveVmConfig' + $cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + + It 'Should not throw with -WhatIf (no session required)' { + { Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Memory 4096 -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + + It 'Should not throw with -WhatIf and multiple config params' { + { Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Cores 4 -Sockets 2 -Memory 8192 -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + } + + Context 'Without active session' { + It 'Should throw when no session is active (without -WhatIf)' { + { Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Memory 4096 -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Set-PveVmConfig -Node 'pve-node1' -VmId 100 -Cores 2 -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +} + +# --------------------------------------------------------------------------- +# Resize-PveVmDisk +# --------------------------------------------------------------------------- +Describe 'Resize-PveVmDisk' { + + Context 'Command existence' { + It 'Should be available after module import' { + Get-Command 'Resize-PveVmDisk' -ErrorAction SilentlyContinue | + Should -Not -BeNullOrEmpty + } + + It 'Should be a CmdletInfo (binary cmdlet)' { + (Get-Command 'Resize-PveVmDisk').CommandType | Should -Be 'Cmdlet' + } + } + + Context 'Parameter metadata' { + BeforeAll { + $script:Cmd = Get-Command 'Resize-PveVmDisk' + } + + It 'Should have Node parameter' { + $script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue + } + + It 'Node should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Node should be of type String' { + $script:Cmd.Parameters['Node'].ParameterType | Should -Be ([string]) + } + + It 'Node should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['Node'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have VmId parameter' { + $script:Cmd.Parameters.ContainsKey('VmId') | Should -BeTrue + } + + It 'VmId should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'VmId should be of type Int32' { + $script:Cmd.Parameters['VmId'].ParameterType | Should -Be ([int]) + } + + It 'VmId should accept pipeline input by property name' { + $acceptsByPropName = $script:Cmd.Parameters['VmId'].ParameterSets.Values | + Where-Object { $_.ValueFromPipelineByPropertyName } + $acceptsByPropName | Should -Not -BeNullOrEmpty + } + + It 'Should have Disk parameter' { + $script:Cmd.Parameters.ContainsKey('Disk') | Should -BeTrue + } + + It 'Disk should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Disk'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Disk should be of type String' { + $script:Cmd.Parameters['Disk'].ParameterType | Should -Be ([string]) + } + + It 'Should have Size parameter' { + $script:Cmd.Parameters.ContainsKey('Size') | Should -BeTrue + } + + It 'Size should be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Size'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + } + + It 'Size should be of type String' { + $script:Cmd.Parameters['Size'].ParameterType | Should -Be ([string]) + } + + It 'Should have Wait switch parameter' { + $script:Cmd.Parameters.ContainsKey('Wait') | Should -BeTrue + $script:Cmd.Parameters['Wait'].ParameterType | + Should -Be ([System.Management.Automation.SwitchParameter]) + } + + It 'Wait should not be Mandatory' { + $isMandatory = $script:Cmd.Parameters['Wait'].ParameterSets.Values | + Where-Object { $_.IsMandatory } + $isMandatory | Should -BeNullOrEmpty + } + + It 'Should have Session parameter (inherited from PveCmdletBase)' { + $script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue + } + } + + Context 'ShouldProcess support' { + It 'Should support ShouldProcess (WhatIf parameter exists)' { + $cmd = Get-Command 'Resize-PveVmDisk' + $cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue + } + + It 'Should support Confirm parameter' { + $cmd = Get-Command 'Resize-PveVmDisk' + $cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue + } + + It 'Should not throw with -WhatIf (no session required)' { + { Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'scsi0' -Size '+10G' -WhatIf -ErrorAction Stop } | + Should -Not -Throw + } + } + + Context 'Without active session' { + It 'Should throw when no session is active (without -WhatIf)' { + { Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'scsi0' -Size '50G' -ErrorAction Stop } | + Should -Throw '*No active Proxmox VE session*' + } + + It 'Should throw PveNotConnectedException type' { + try { + Resize-PveVmDisk -Node 'pve-node1' -VmId 100 -Disk 'virtio0' -Size '+5G' -ErrorAction Stop + } + catch { + $_.Exception.GetType().Name | Should -Match 'PveNotConnectedException|CmdletInvocationException' + } + } + } +}