mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-09-07 12:35:41 +00:00
089bb7c81e
* refactor: one task-response parser, and the dead code #154 names (part A) Unifies the 8 byte-similar private ParseTask methods in BackupService, ContainerService, NetworkService, NodeService, SnapshotService, StorageService, TemplateService, and VmService into one shared PveTaskResponse.Parse(json, node) utility, on the variant that stamps Status = "running" for a bare-UPID response. BackupService, NodeService, TemplateService, and VmService previously left Status null for that case; their non--Wait task output now reports "running" like the other four services already did. Removes the duplicate ClusterConfigService.GetClusterStatus in favor of ClusterService's; ClusterConfigService now holds a ClusterService built from the same injected/default client, and WaitForQuorum and Get-PveClusterStatus go through it. Removes dead code named in issue #154 and its fold-in comments: the never-called PveHttpClient/IPveHttpClient sync wrappers Put/Delete, the never-thrown PveAuthenticationException, a #pragma around an already-nullable field, the unreferenced TestHelper mock-handler helpers, three hand-rolled version-warning blocks (now PveCmdletBase.WarnIfBelowVersion), an unreachable catch(HttpRequestException) arm in WaitForStatusTransition, dead ExitStatus-checking branches in ImportPveOvaCmdlet after WaitForTask (which already throws on failure), and an unreachable int branch in ApiValueHelper.IsExited. Fixes the WaitForStatusTransition catch removal's premise: PveHttpClient read the response body outside its HttpRequestException try block, so a mid-body stream drop could still escape unwrapped. Moves the body read inside the try so every HttpRequestException the client can throw becomes a PveApiException, matching what the removed catch assumed. Part of #154. * Add service files: BackupService, ClusterConfigService, ContainerService, NetworkService * Add service files: NodeService, SnapshotService, StorageService, TemplateService * Add VmService and Utilities files * Remove unused PveAuthenticationException (never thrown, caught, or tested) * Add cmdlet files: GetPveClusterStatus, SDN subnets, PveCmdletBase, SendPveFile, ImportPveOva * Add test files: BackupServiceTests, ClusterConfigServiceTests, NodeServiceTests * Add remaining test files: TemplateServiceTests, VmServiceTests, TestHelper, ApiValueHelperTests, PveTaskResponseTests * Add VmServiceTests --------- Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using PSProxmoxVE.Core.Utilities;
|
|
using Xunit;
|
|
|
|
namespace PSProxmoxVE.Core.Tests.Utilities
|
|
{
|
|
public class ApiValueHelperTests
|
|
{
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(1L)]
|
|
[InlineData("1")]
|
|
public void IsExited_TrueValues_ReturnsTrue(object value)
|
|
{
|
|
Assert.True(ApiValueHelper.IsExited(value));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(0L)]
|
|
[InlineData("0")]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("true")]
|
|
[InlineData(2L)]
|
|
[InlineData(1)]
|
|
[InlineData(42)]
|
|
public void IsExited_FalseValues_ReturnsFalse(object? value)
|
|
{
|
|
Assert.False(ApiValueHelper.IsExited(value));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{\"data\":{\"exited\":true}}", true)]
|
|
[InlineData("{\"data\":{\"exited\":false}}", false)]
|
|
[InlineData("{\"data\":{\"exited\":1}}", true)]
|
|
[InlineData("{\"data\":{\"exited\":0}}", false)]
|
|
[InlineData("{\"data\":{\"exited\":\"1\"}}", true)]
|
|
[InlineData("{\"data\":{\"exited\":\"0\"}}", false)]
|
|
[InlineData("{\"data\":{\"exited\":null}}", false)]
|
|
[InlineData("{\"data\":{}}", false)]
|
|
public void IsExited_ApiJsonValues_ReturnExpectedCompletionState(string json, bool expected)
|
|
{
|
|
var data = (JObject)JObject.Parse(json)["data"]!;
|
|
var status = JsonHelper.ToDictionary(data);
|
|
var completed = status.TryGetValue("exited", out var exited) && ApiValueHelper.IsExited(exited);
|
|
|
|
Assert.Equal(expected, completed);
|
|
}
|
|
}
|
|
}
|