mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-08 21:43:12 +00:00
8ea983c0fc
- BaseUrl trailing slash and resource path cleanup: PveSession.BaseUrl now
ends with '/', all cmdlet resource strings stripped of leading slashes and
/api2/json/ prefixes so URLs compose correctly
- PveNodeStatus: rename Name -> Node to match JSON field and test expectations
- NewPveVmCmdlet: auto-allocate vmid via GET cluster/nextid when -VmId omitted
- UploadFileAsync (BZ 7389 workarounds):
* Unquoted multipart boundary in Content-Type header
* Quoted name= values in Content-Disposition (embedded double-quotes)
* Content-Disposition set before Content-Type on file part — PVE's parser
closes the connection if Content-Type appears first
- SendPveIsoCmdlet: run upload in Task.Run, track progress atomically with
Interlocked, poll and call WriteProgress only from pipeline thread to avoid
InvalidOperationException from PSCmdlet thread-affinity requirements
- Add debug/Capture-UploadDiff.ps1: mitmproxy capture script used to isolate
the header-ordering bug by diffing raw multipart bytes from PS vs C# module
Integration test result: 11 passed, 0 failed, 4 skipped (expected — no
template/stopped VMs on bare nested PVE test node).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using PSProxmoxVE.Core.Models.Nodes;
|
|
|
|
namespace PSProxmoxVE.Core.Tests.Models
|
|
{
|
|
public class NodeModelTests
|
|
{
|
|
[Fact]
|
|
public void PveNode_Deserialize_Pve9()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_nodes.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var nodes = data.ToObject<PveNode[]>();
|
|
Assert.NotNull(nodes);
|
|
Assert.Equal(2, nodes.Length);
|
|
Assert.Equal("pve1", nodes[0].Name);
|
|
Assert.Equal("online", nodes[0].Status);
|
|
Assert.Equal(16, nodes[0].CpuCount);
|
|
Assert.Equal(68719476736L, nodes[0].MemoryTotal);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNode_Deserialize_Pve9_SecondNode()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_nodes.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var nodes = data.ToObject<PveNode[]>();
|
|
Assert.NotNull(nodes);
|
|
Assert.Equal("pve2", nodes[1].Name);
|
|
Assert.Equal("online", nodes[1].Status);
|
|
Assert.Equal(8, nodes[1].CpuCount);
|
|
Assert.Equal(34359738368L, nodes[1].MemoryTotal);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNode_Deserialize_Pve8()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve8_nodes.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var nodes = data.ToObject<PveNode[]>();
|
|
Assert.NotNull(nodes);
|
|
Assert.Single(nodes);
|
|
Assert.Equal("pve-old", nodes[0].Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNode_Deserialize_Pve8_HasExpectedCpuAndMemory()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve8_nodes.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var nodes = data.ToObject<PveNode[]>();
|
|
Assert.NotNull(nodes);
|
|
Assert.Equal(4, nodes[0].CpuCount);
|
|
Assert.Equal(16106127360L, nodes[0].MemoryTotal);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNodeStatus_Deserialize_Pve9()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_node_status.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var status = data.ToObject<PveNodeStatus>();
|
|
Assert.NotNull(status);
|
|
Assert.Equal(0.125, status.CpuUsage);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNodeStatus_Deserialize_Pve9_HasMemoryAndUptime()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_node_status.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var status = data.ToObject<PveNodeStatus>();
|
|
Assert.NotNull(status);
|
|
Assert.Equal("pve1", status.Node);
|
|
Assert.Equal(68719476736L, status.MemoryTotal);
|
|
Assert.Equal(17179869184L, status.MemoryUsed);
|
|
Assert.Equal(864000L, status.Uptime);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNodeStatus_MemoryUsage_IsCalculated()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_node_status.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var status = data.ToObject<PveNodeStatus>();
|
|
Assert.NotNull(status);
|
|
Assert.NotNull(status.MemoryUsage);
|
|
// 17179869184 / 68719476736 * 100 = 25.0
|
|
Assert.Equal(25.0, status.MemoryUsage!.Value, precision: 5);
|
|
}
|
|
|
|
[Fact]
|
|
public void PveNode_LoadAverage_IsDeserializedAsArray()
|
|
{
|
|
var json = TestHelper.LoadFixture("pve9_nodes.json");
|
|
var data = JObject.Parse(json)["data"];
|
|
var nodes = data.ToObject<PveNode[]>();
|
|
Assert.NotNull(nodes);
|
|
Assert.NotNull(nodes[0].LoadAverage);
|
|
Assert.Equal(3, nodes[0].LoadAverage!.Length);
|
|
}
|
|
}
|
|
}
|