mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-07-26 07:58:14 +00:00
fix: normalize -DiskSize and -RootFsSize before sending to PVE
Disk and rootfs size strings were interpolated directly into the disk spec as "<storage>:<size>", so "60G" produced "local-lvm:60G". On LVM/LVM-thin storages PVE parses the value after the colon as a volume name unless it is a bare integer, returning "unable to parse lvm volume name '60G'". File-backed storages mask this by accepting either form. SizeParser.NormalizeToGibibytes() now strips G/GB/T/TB suffixes and returns a bare GiB integer string, so the documented "32G" call shape works on every storage type. Sub-GB units are rejected with a clear error rather than being silently truncated. Tracked as F086. Closes #58. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user