mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-19 09:26:17 +00:00
Merge main into fix/http-client-timeout
Resolves findings.json conflict — F086 (from #60, merged into main) and F087 (this branch) both append to the trailing findings array. Kept both entries, in numeric order. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using PSProxmoxVE.Core.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace PSProxmoxVE.Core.Tests.Utilities
|
||||
{
|
||||
public class SizeParserTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("32", "32")]
|
||||
[InlineData("32G", "32")]
|
||||
[InlineData("32g", "32")]
|
||||
[InlineData("32GB", "32")]
|
||||
[InlineData("32gb", "32")]
|
||||
[InlineData("32GiB", "32")]
|
||||
[InlineData("1T", "1024")]
|
||||
[InlineData("1t", "1024")]
|
||||
[InlineData("1TB", "1024")]
|
||||
[InlineData("1TiB", "1024")]
|
||||
[InlineData("2T", "2048")]
|
||||
[InlineData(" 60G ", "60")]
|
||||
[InlineData("60 G", "60")]
|
||||
public void NormalizeToGibibytes_AcceptedInputs_ReturnsBareGibibyteString(string input, string expected)
|
||||
{
|
||||
var result = SizeParser.NormalizeToGibibytes(input);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("512M")]
|
||||
[InlineData("512MB")]
|
||||
[InlineData("1024K")]
|
||||
[InlineData("1024KB")]
|
||||
[InlineData("100B")]
|
||||
[InlineData("1P")]
|
||||
[InlineData("1PB")]
|
||||
public void NormalizeToGibibytes_UnsupportedUnit_Throws(string input)
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes(input));
|
||||
Assert.Contains("unsupported unit", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void NormalizeToGibibytes_EmptyOrWhitespace_Throws(string? input)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes(input!));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("abc")]
|
||||
[InlineData("G")]
|
||||
[InlineData("-32")]
|
||||
[InlineData("32.5G")]
|
||||
[InlineData("32 G B")]
|
||||
public void NormalizeToGibibytes_Malformed_Throws(string input)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes(input));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("0G")]
|
||||
public void NormalizeToGibibytes_Zero_Throws(string input)
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes(input));
|
||||
Assert.Contains("positive", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NormalizeToGibibytes_UsesProvidedParameterNameInError()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes("512M", "DiskSize"));
|
||||
Assert.Equal("DiskSize", ex.ParamName);
|
||||
Assert.Contains("DiskSize", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NormalizeToGibibytes_TerabyteOverflow_ThrowsArgumentException()
|
||||
{
|
||||
// long.MaxValue with a T suffix overflows when multiplied by 1024.
|
||||
var input = long.MaxValue.ToString(System.Globalization.CultureInfo.InvariantCulture) + "T";
|
||||
var ex = Assert.Throws<ArgumentException>(() => SizeParser.NormalizeToGibibytes(input, "DiskSize"));
|
||||
Assert.Equal("DiskSize", ex.ParamName);
|
||||
Assert.Contains("too large", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#Requires -Module Pester
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Pester 5 tests for New-PveContainer.
|
||||
All tests are fully offline — no live Proxmox VE target is required.
|
||||
#>
|
||||
|
||||
BeforeAll {
|
||||
. $PSScriptRoot/../_TestHelper.ps1
|
||||
}
|
||||
|
||||
Describe 'New-PveContainer' {
|
||||
|
||||
Context 'Command existence' {
|
||||
It 'Should be available after module import' {
|
||||
Get-Command 'New-PveContainer' -ErrorAction SilentlyContinue |
|
||||
Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Should be a CmdletInfo (binary cmdlet)' {
|
||||
(Get-Command 'New-PveContainer').CommandType | Should -Be 'Cmdlet'
|
||||
}
|
||||
}
|
||||
|
||||
Context 'ShouldProcess support' {
|
||||
BeforeAll {
|
||||
$script:Cmd = Get-Command 'New-PveContainer'
|
||||
}
|
||||
|
||||
It 'Should support ShouldProcess (WhatIf parameter present)' {
|
||||
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should support ShouldProcess (Confirm parameter present)' {
|
||||
$script:Cmd.Parameters.ContainsKey('Confirm') | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
Context 'RootFsSize validation' {
|
||||
# Validation runs before ShouldProcess so -WhatIf is enough to exercise it
|
||||
# without an active session.
|
||||
|
||||
It 'Should reject sub-GB units (e.g. 512M)' {
|
||||
{ New-PveContainer -Node 'pve-node1' -RootFsStorage 'local-lvm' -RootFsSize '512M' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*unsupported unit*'
|
||||
}
|
||||
|
||||
It 'Should reject sub-GB units even when -RootFsStorage is omitted' {
|
||||
{ New-PveContainer -Node 'pve-node1' -RootFsSize '512M' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*unsupported unit*'
|
||||
}
|
||||
|
||||
It 'Should reject malformed input (e.g. 8.5G)' {
|
||||
{ New-PveContainer -Node 'pve-node1' -RootFsStorage 'local-lvm' -RootFsSize '8.5G' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*not a valid size*'
|
||||
}
|
||||
|
||||
It 'Should accept a bare integer with -WhatIf' {
|
||||
{ New-PveContainer -Node 'pve-node1' -RootFsStorage 'local-lvm' -RootFsSize '8' -WhatIf -ErrorAction Stop } |
|
||||
Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should accept "8G" with -WhatIf' {
|
||||
{ New-PveContainer -Node 'pve-node1' -RootFsStorage 'local-lvm' -RootFsSize '8G' -WhatIf -ErrorAction Stop } |
|
||||
Should -Not -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,4 +133,39 @@ Describe 'New-PveVm' {
|
||||
Should -Throw '*No active Proxmox VE session*'
|
||||
}
|
||||
}
|
||||
|
||||
Context 'DiskSize validation' {
|
||||
# Validation runs before ShouldProcess so -WhatIf is enough to exercise it
|
||||
# without an active session.
|
||||
|
||||
It 'Should reject sub-GB units (e.g. 512M)' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '512M' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*unsupported unit*'
|
||||
}
|
||||
|
||||
It 'Should reject sub-GB units even when -DiskStorage is omitted' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskSize '512M' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*unsupported unit*'
|
||||
}
|
||||
|
||||
It 'Should reject malformed input (e.g. 32.5G)' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '32.5G' -WhatIf -ErrorAction Stop } |
|
||||
Should -Throw '*not a valid size*'
|
||||
}
|
||||
|
||||
It 'Should accept a bare integer with -WhatIf' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '32' -WhatIf -ErrorAction Stop } |
|
||||
Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should accept "32G" with -WhatIf' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '32G' -WhatIf -ErrorAction Stop } |
|
||||
Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should accept "1T" with -WhatIf' {
|
||||
{ New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '1T' -WhatIf -ErrorAction Stop } |
|
||||
Should -Not -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user