mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-07-26 16:28:16 +00:00
Remove test folder and add Release folder with module package
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class GetProxmoxClusterBackupCmdletTests
|
||||
{
|
||||
private Mock<ProxmoxConnection> _mockConnection;
|
||||
private Mock<ProxmoxApiClient> _mockClient;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_mockConnection = new Mock<ProxmoxConnection>("test.proxmox.com");
|
||||
_mockClient = new Mock<ProxmoxApiClient>(_mockConnection.Object, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_NoBackupID_ReturnsAllBackups()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new GetProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object
|
||||
};
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/backup"))
|
||||
.Returns("{\"data\":[{\"backup-id\":\"vzdump-cluster-2023_04_28-12_00_00.vma.lzo\",\"time\":1682683200,\"type\":\"cluster\",\"version\":\"7.2-3\",\"size\":1024000,\"compression\":\"lzo\",\"node\":\"pve1\",\"path\":\"/var/lib/vz/dump/vzdump-cluster-2023_04_28-12_00_00.vma.lzo\"}]}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithBackupID_ReturnsSpecificBackup()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new GetProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
BackupID = "vzdump-cluster-2023_04_28-12_00_00.vma.lzo"
|
||||
};
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/backup"))
|
||||
.Returns("{\"data\":[{\"backup-id\":\"vzdump-cluster-2023_04_28-12_00_00.vma.lzo\",\"time\":1682683200,\"type\":\"cluster\",\"version\":\"7.2-3\",\"size\":1024000,\"compression\":\"lzo\",\"node\":\"pve1\",\"path\":\"/var/lib/vz/dump/vzdump-cluster-2023_04_28-12_00_00.vma.lzo\"}]}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception))]
|
||||
public void ProcessRecord_BackupNotFound_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new GetProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
BackupID = "nonexistent-backup"
|
||||
};
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/backup"))
|
||||
.Returns("{\"data\":[{\"backup-id\":\"vzdump-cluster-2023_04_28-12_00_00.vma.lzo\",\"time\":1682683200,\"type\":\"cluster\",\"version\":\"7.2-3\",\"size\":1024000,\"compression\":\"lzo\",\"node\":\"pve1\",\"path\":\"/var/lib/vz/dump/vzdump-cluster-2023_04_28-12_00_00.vma.lzo\"}]}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// The test should throw an exception
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class NewProxmoxClusterBackupCmdletTests
|
||||
{
|
||||
private Mock<ProxmoxConnection> _mockConnection;
|
||||
private Mock<ProxmoxApiClient> _mockClient;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_mockConnection = new Mock<ProxmoxConnection>("test.proxmox.com");
|
||||
_mockClient = new Mock<ProxmoxApiClient>(_mockConnection.Object, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_CreatesBackup()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Compress = true
|
||||
};
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Post("cluster/backup", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("cluster/backup"))
|
||||
.Returns("{\"data\":[{\"backup-id\":\"vzdump-cluster-2023_04_28-12_00_00.vma.lzo\",\"time\":1682683200,\"type\":\"cluster\",\"version\":\"7.2-3\",\"size\":1024000,\"compression\":\"lzo\",\"node\":\"pve1\",\"path\":\"/var/lib/vz/dump/vzdump-cluster-2023_04_28-12_00_00.vma.lzo\"}]}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithWait_WaitsForBackupToComplete()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Compress = true,
|
||||
Wait = true,
|
||||
Timeout = 60
|
||||
};
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Post("cluster/backup", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/test.proxmox.com/tasks/UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:/status"))
|
||||
.Returns("{\"data\":{\"status\":\"stopped\"}}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("cluster/backup"))
|
||||
.Returns("{\"data\":[{\"backup-id\":\"vzdump-cluster-2023_04_28-12_00_00.vma.lzo\",\"time\":1682683200,\"type\":\"cluster\",\"version\":\"7.2-3\",\"size\":1024000,\"compression\":\"lzo\",\"node\":\"pve1\",\"path\":\"/var/lib/vz/dump/vzdump-cluster-2023_04_28-12_00_00.vma.lzo\"}]}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class NewProxmoxVMBuilderCmdletTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProcessRecord_CreatesBuilder()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = "test-vm",
|
||||
Memory = 2048,
|
||||
Cores = 2,
|
||||
CPUType = "host",
|
||||
OSType = "l26",
|
||||
Start = true,
|
||||
IPPool = "test-pool"
|
||||
};
|
||||
|
||||
// Act
|
||||
ProxmoxVMBuilder result = null;
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
var results = ps.Invoke();
|
||||
|
||||
// Get the result
|
||||
if (results.Count > 0)
|
||||
{
|
||||
result = results[0].BaseObject as ProxmoxVMBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("test-vm", result.Name);
|
||||
Assert.AreEqual(2048, result.Memory);
|
||||
Assert.AreEqual(2, result.Cores);
|
||||
Assert.AreEqual("host", result.CPUType);
|
||||
Assert.AreEqual("l26", result.OSType);
|
||||
Assert.IsTrue(result.Start);
|
||||
Assert.AreEqual("test-pool", result.IPPool);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(PSArgumentNullException))]
|
||||
public void ProcessRecord_ThrowsOnNullName()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = null
|
||||
};
|
||||
|
||||
// Act
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
ps.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithNode_CreatesBuilder()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = "test-vm",
|
||||
Node = "pve1"
|
||||
};
|
||||
|
||||
// Act
|
||||
ProxmoxVMBuilder result = null;
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
var results = ps.Invoke();
|
||||
|
||||
// Get the result
|
||||
if (results.Count > 0)
|
||||
{
|
||||
result = results[0].BaseObject as ProxmoxVMBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("test-vm", result.Name);
|
||||
Assert.AreEqual("pve1", result.Node);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithVMID_CreatesBuilder()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = "test-vm",
|
||||
VMID = 100
|
||||
};
|
||||
|
||||
// Act
|
||||
ProxmoxVMBuilder result = null;
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
var results = ps.Invoke();
|
||||
|
||||
// Get the result
|
||||
if (results.Count > 0)
|
||||
{
|
||||
result = results[0].BaseObject as ProxmoxVMBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("test-vm", result.Name);
|
||||
Assert.AreEqual(100, result.VMID);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithDescription_CreatesBuilder()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = "test-vm",
|
||||
Description = "Test VM"
|
||||
};
|
||||
|
||||
// Act
|
||||
ProxmoxVMBuilder result = null;
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
var results = ps.Invoke();
|
||||
|
||||
// Get the result
|
||||
if (results.Count > 0)
|
||||
{
|
||||
result = results[0].BaseObject as ProxmoxVMBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("test-vm", result.Name);
|
||||
Assert.AreEqual("Test VM", result.Description);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithTags_CreatesBuilder()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMBuilderCmdlet
|
||||
{
|
||||
Name = "test-vm",
|
||||
Tags = new[] { "tag1", "tag2" }
|
||||
};
|
||||
|
||||
// Act
|
||||
ProxmoxVMBuilder result = null;
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = RunspaceFactory.CreateRunspace();
|
||||
ps.Runspace.Open();
|
||||
|
||||
// Add the cmdlet to the pipeline
|
||||
ps.Commands.AddCommand(cmdlet);
|
||||
|
||||
// Execute the cmdlet
|
||||
var results = ps.Invoke();
|
||||
|
||||
// Get the result
|
||||
if (results.Count > 0)
|
||||
{
|
||||
result = results[0].BaseObject as ProxmoxVMBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("test-vm", result.Name);
|
||||
Assert.AreEqual("tag1,tag2", result.Tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class NewProxmoxVMCmdletTests
|
||||
{
|
||||
private Mock<ProxmoxConnection> _mockConnection;
|
||||
private Mock<ProxmoxApiClient> _mockClient;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_mockConnection = new Mock<ProxmoxConnection>("test.proxmox.com");
|
||||
_mockClient = new Mock<ProxmoxApiClient>(_mockConnection.Object, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_DirectParameters_CreatesVM()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Node = "pve1",
|
||||
Name = "test-vm",
|
||||
Memory = 2048,
|
||||
Cores = 2,
|
||||
DiskSize = 32,
|
||||
Storage = "local-lvm",
|
||||
OSType = "l26",
|
||||
NetworkModel = "virtio",
|
||||
NetworkBridge = "vmbr0",
|
||||
Start = true
|
||||
};
|
||||
|
||||
// Set up the parameter set name using reflection
|
||||
typeof(PSCmdlet).GetProperty("ParameterSetName", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(cmdlet, "Direct");
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/nextid"))
|
||||
.Returns("{\"data\":\"100\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/pve1/qemu/100/status/current"))
|
||||
.Returns("{\"data\":{\"vmid\":100,\"name\":\"test-vm\",\"status\":\"stopped\"}}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/100/status/start", null))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_Builder_CreatesVM()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm")
|
||||
.WithMemory(2048)
|
||||
.WithCores(2)
|
||||
.WithDisk(32, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithStart(true);
|
||||
|
||||
var cmdlet = new NewProxmoxVMCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Node = "pve1",
|
||||
Builder = builder
|
||||
};
|
||||
|
||||
// Set up the parameter set name using reflection
|
||||
typeof(PSCmdlet).GetProperty("ParameterSetName", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(cmdlet, "Builder");
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/nextid"))
|
||||
.Returns("{\"data\":\"100\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/pve1/qemu/100/status/current"))
|
||||
.Returns("{\"data\":{\"vmid\":100,\"name\":\"test-vm\",\"status\":\"stopped\"}}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/100/status/start", null))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
using PSProxmox.Templates;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class NewProxmoxVMFromTemplateCmdletTests
|
||||
{
|
||||
private Mock<ProxmoxConnection> _mockConnection;
|
||||
private Mock<ProxmoxApiClient> _mockClient;
|
||||
private Mock<TemplateManager> _mockTemplateManager;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_mockConnection = new Mock<ProxmoxConnection>("test.proxmox.com");
|
||||
_mockClient = new Mock<ProxmoxApiClient>(_mockConnection.Object, null);
|
||||
_mockTemplateManager = new Mock<TemplateManager>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_SingleVM_CreatesVMFromTemplate()
|
||||
{
|
||||
// Arrange
|
||||
var template = new ProxmoxVMTemplate
|
||||
{
|
||||
Name = "Ubuntu-Template",
|
||||
VMID = 100,
|
||||
Node = "pve1",
|
||||
CPUs = 2,
|
||||
MaxMemory = 2048 * 1024 * 1024,
|
||||
MaxDisk = 32 * 1024 * 1024 * 1024
|
||||
};
|
||||
|
||||
var cmdlet = new NewProxmoxVMFromTemplateCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Node = "pve1",
|
||||
TemplateName = "Ubuntu-Template",
|
||||
Name = "web01",
|
||||
Start = true
|
||||
};
|
||||
|
||||
// Set up the parameter set name using reflection
|
||||
typeof(PSCmdlet).GetProperty("ParameterSetName", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(cmdlet, "SingleVM");
|
||||
|
||||
// Mock the template manager
|
||||
TemplateManager.GetTemplate("Ubuntu-Template").Returns(template);
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/nextid"))
|
||||
.Returns("{\"data\":\"101\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/100/clone", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/pve1/qemu/101/status/current"))
|
||||
.Returns("{\"data\":{\"vmid\":101,\"name\":\"web01\",\"status\":\"stopped\"}}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/101/status/start", null))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_MultipleVMs_CreatesMultipleVMsFromTemplate()
|
||||
{
|
||||
// Arrange
|
||||
var template = new ProxmoxVMTemplate
|
||||
{
|
||||
Name = "Ubuntu-Template",
|
||||
VMID = 100,
|
||||
Node = "pve1",
|
||||
CPUs = 2,
|
||||
MaxMemory = 2048 * 1024 * 1024,
|
||||
MaxDisk = 32 * 1024 * 1024 * 1024
|
||||
};
|
||||
|
||||
var cmdlet = new NewProxmoxVMFromTemplateCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Node = "pve1",
|
||||
TemplateName = "Ubuntu-Template",
|
||||
Prefix = "web",
|
||||
Count = 3,
|
||||
StartIndex = 1,
|
||||
Start = true
|
||||
};
|
||||
|
||||
// Set up the parameter set name using reflection
|
||||
typeof(PSCmdlet).GetProperty("ParameterSetName", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(cmdlet, "MultipleVMs");
|
||||
|
||||
// Mock the template manager
|
||||
TemplateManager.GetTemplate("Ubuntu-Template").Returns(template);
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Get("cluster/nextid"))
|
||||
.Returns("{\"data\":\"101\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/100/clone", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/pve1/qemu/101/status/current"))
|
||||
.Returns("{\"data\":{\"vmid\":101,\"name\":\"web1\",\"status\":\"stopped\"}}");
|
||||
|
||||
_mockClient.Setup(c => c.Post("nodes/pve1/qemu/101/status/start", null))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception))]
|
||||
public void ProcessRecord_TemplateNotFound_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new NewProxmoxVMFromTemplateCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
Node = "pve1",
|
||||
TemplateName = "NonExistentTemplate",
|
||||
Name = "web01"
|
||||
};
|
||||
|
||||
// Set up the parameter set name using reflection
|
||||
typeof(PSCmdlet).GetProperty("ParameterSetName", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
.SetValue(cmdlet, "SingleVM");
|
||||
|
||||
// Mock the template manager to throw an exception
|
||||
TemplateManager.GetTemplate("NonExistentTemplate").Throws(new Exception("Template not found"));
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// The test should throw an exception
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Cmdlets;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PSProxmox.Tests.Cmdlets
|
||||
{
|
||||
[TestClass]
|
||||
public class RestoreProxmoxClusterBackupCmdletTests
|
||||
{
|
||||
private Mock<ProxmoxConnection> _mockConnection;
|
||||
private Mock<ProxmoxApiClient> _mockClient;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_mockConnection = new Mock<ProxmoxConnection>("test.proxmox.com");
|
||||
_mockClient = new Mock<ProxmoxApiClient>(_mockConnection.Object, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_RestoresBackup()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new RestoreProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
BackupID = "vzdump-cluster-2023_04_28-12_00_00.vma.lzo",
|
||||
Force = true
|
||||
};
|
||||
|
||||
// Set ShouldProcess to return true using reflection
|
||||
var shouldProcessMethod = typeof(PSCmdlet).GetMethod("ShouldProcess", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(string), typeof(string) }, null);
|
||||
var mockShouldProcess = new Mock<Func<string, string, bool>>();
|
||||
mockShouldProcess.Setup(f => f(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
|
||||
shouldProcessMethod.Invoke(cmdlet, new object[] { "Cluster backup vzdump-cluster-2023_04_28-12_00_00.vma.lzo", "Restore" });
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Post("cluster/backup/restore", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_WithWait_WaitsForRestoreToComplete()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new RestoreProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
BackupID = "vzdump-cluster-2023_04_28-12_00_00.vma.lzo",
|
||||
Force = true,
|
||||
Wait = true,
|
||||
Timeout = 600
|
||||
};
|
||||
|
||||
// Set ShouldProcess to return true using reflection
|
||||
var shouldProcessMethod = typeof(PSCmdlet).GetMethod("ShouldProcess", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(string), typeof(string) }, null);
|
||||
var mockShouldProcess = new Mock<Func<string, string, bool>>();
|
||||
mockShouldProcess.Setup(f => f(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
|
||||
shouldProcessMethod.Invoke(cmdlet, new object[] { "Cluster backup vzdump-cluster-2023_04_28-12_00_00.vma.lzo", "Restore" });
|
||||
|
||||
// Mock the API client
|
||||
_mockClient.Setup(c => c.Post("cluster/backup/restore", It.IsAny<System.Collections.Generic.Dictionary<string, string>>()))
|
||||
.Returns("{\"data\":\"UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:\"}");
|
||||
|
||||
_mockClient.Setup(c => c.Get("nodes/test.proxmox.com/tasks/UPID:pve1:00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000:/status"))
|
||||
.Returns("{\"data\":{\"status\":\"stopped\"}}");
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert the output, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessRecord_ShouldProcessReturnsFalse_DoesNotRestoreBackup()
|
||||
{
|
||||
// Arrange
|
||||
var cmdlet = new RestoreProxmoxClusterBackupCmdlet
|
||||
{
|
||||
Connection = _mockConnection.Object,
|
||||
BackupID = "vzdump-cluster-2023_04_28-12_00_00.vma.lzo",
|
||||
Force = true
|
||||
};
|
||||
|
||||
// Set ShouldProcess to return false using reflection
|
||||
var shouldProcessMethod = typeof(PSCmdlet).GetMethod("ShouldProcess", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(string), typeof(string) }, null);
|
||||
var mockShouldProcess = new Mock<Func<string, string, bool>>();
|
||||
mockShouldProcess.Setup(f => f(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
|
||||
shouldProcessMethod.Invoke(cmdlet, new object[] { "Cluster backup vzdump-cluster-2023_04_28-12_00_00.vma.lzo", "Restore" });
|
||||
|
||||
// Act
|
||||
// In a real test, we would call ProcessRecord, but for simplicity, we'll just verify the mocks
|
||||
|
||||
// Assert
|
||||
// In a real test, we would assert that the API client was not called, but for simplicity, we'll just verify the mocks
|
||||
Assert.IsNotNull(cmdlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PSProxmox.IPAM;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace PSProxmox.Tests.IPAM
|
||||
{
|
||||
[TestClass]
|
||||
public class IPAMManagerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CreatePool_CreatesPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
string name = "test-pool";
|
||||
string cidr = "192.168.1.0/24";
|
||||
|
||||
// Act
|
||||
var pool = ipamManager.CreatePool(name, cidr);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, pool.Name);
|
||||
Assert.AreEqual(cidr, pool.CIDR);
|
||||
Assert.AreEqual(254, pool.TotalIPs); // 256 - 2 (network and broadcast)
|
||||
Assert.AreEqual(254, pool.AvailableIPs);
|
||||
Assert.AreEqual(0, pool.UsedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreatePool_WithExcludedIPs_CreatesPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
string name = "test-pool";
|
||||
string cidr = "192.168.1.0/24";
|
||||
string[] excludeIPs = new[] { "192.168.1.1", "192.168.1.254" };
|
||||
|
||||
// Act
|
||||
var pool = ipamManager.CreatePool(name, cidr, excludeIPs);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, pool.Name);
|
||||
Assert.AreEqual(cidr, pool.CIDR);
|
||||
Assert.AreEqual(254, pool.TotalIPs);
|
||||
Assert.AreEqual(252, pool.AvailableIPs); // 254 - 2 excluded
|
||||
Assert.AreEqual(0, pool.UsedIPs);
|
||||
Assert.AreEqual(2, pool.ExcludedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetPool_ReturnsPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
string name = "test-pool";
|
||||
string cidr = "192.168.1.0/24";
|
||||
ipamManager.CreatePool(name, cidr);
|
||||
|
||||
// Act
|
||||
var pool = ipamManager.GetPool(name);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, pool.Name);
|
||||
Assert.AreEqual(cidr, pool.CIDR);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(KeyNotFoundException))]
|
||||
public void GetPool_ThrowsOnNonExistentPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
|
||||
// Act
|
||||
var pool = ipamManager.GetPool("non-existent-pool");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetPools_ReturnsAllPools()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
ipamManager.CreatePool("pool1", "192.168.1.0/24");
|
||||
ipamManager.CreatePool("pool2", "192.168.2.0/24");
|
||||
|
||||
// Act
|
||||
var pools = ipamManager.GetPools().ToList();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(2, pools.Count);
|
||||
Assert.IsTrue(pools.Any(p => p.Name == "pool1"));
|
||||
Assert.IsTrue(pools.Any(p => p.Name == "pool2"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RemovePool_RemovesPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
ipamManager.CreatePool("pool1", "192.168.1.0/24");
|
||||
ipamManager.CreatePool("pool2", "192.168.2.0/24");
|
||||
|
||||
// Act
|
||||
ipamManager.RemovePool("pool1");
|
||||
var pools = ipamManager.GetPools().ToList();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(1, pools.Count);
|
||||
Assert.IsTrue(pools.Any(p => p.Name == "pool2"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(KeyNotFoundException))]
|
||||
public void RemovePool_ThrowsOnNonExistentPool()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
|
||||
// Act
|
||||
ipamManager.RemovePool("non-existent-pool");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearPools_ClearsAllPools()
|
||||
{
|
||||
// Arrange
|
||||
var ipamManager = new IPAMManager();
|
||||
ipamManager.CreatePool("pool1", "192.168.1.0/24");
|
||||
ipamManager.CreatePool("pool2", "192.168.2.0/24");
|
||||
|
||||
// Act
|
||||
ipamManager.ClearPools();
|
||||
var pools = ipamManager.GetPools().ToList();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(0, pools.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
public class IPPoolTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_InitializesPool()
|
||||
{
|
||||
// Arrange
|
||||
string name = "test-pool";
|
||||
string cidr = "192.168.1.0/24";
|
||||
|
||||
// Act
|
||||
var pool = new IPPool(name, cidr);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, pool.Name);
|
||||
Assert.AreEqual(cidr, pool.CIDR);
|
||||
Assert.AreEqual(IPAddress.Parse("192.168.1.0"), pool.NetworkAddress);
|
||||
Assert.AreEqual(IPAddress.Parse("255.255.255.0"), pool.SubnetMask);
|
||||
Assert.AreEqual(24, pool.PrefixLength);
|
||||
Assert.AreEqual(254, pool.TotalIPs);
|
||||
Assert.AreEqual(254, pool.AvailableIPs);
|
||||
Assert.AreEqual(0, pool.UsedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_WithExcludedIPs_InitializesPool()
|
||||
{
|
||||
// Arrange
|
||||
string name = "test-pool";
|
||||
string cidr = "192.168.1.0/24";
|
||||
string[] excludeIPs = new[] { "192.168.1.1", "192.168.1.254" };
|
||||
|
||||
// Act
|
||||
var pool = new IPPool(name, cidr, excludeIPs);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, pool.Name);
|
||||
Assert.AreEqual(cidr, pool.CIDR);
|
||||
Assert.AreEqual(254, pool.TotalIPs);
|
||||
Assert.AreEqual(252, pool.AvailableIPs);
|
||||
Assert.AreEqual(0, pool.UsedIPs);
|
||||
Assert.AreEqual(2, pool.ExcludedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetNextIP_ReturnsNextIP()
|
||||
{
|
||||
// Arrange
|
||||
var pool = new IPPool("test-pool", "192.168.1.0/24");
|
||||
|
||||
// Act
|
||||
var ip1 = pool.GetNextIP();
|
||||
var ip2 = pool.GetNextIP();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(IPAddress.Parse("192.168.1.1"), ip1);
|
||||
Assert.AreEqual(IPAddress.Parse("192.168.1.2"), ip2);
|
||||
Assert.AreEqual(252, pool.AvailableIPs);
|
||||
Assert.AreEqual(2, pool.UsedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ReleaseIP_ReleasesIP()
|
||||
{
|
||||
// Arrange
|
||||
var pool = new IPPool("test-pool", "192.168.1.0/24");
|
||||
var ip1 = pool.GetNextIP();
|
||||
var ip2 = pool.GetNextIP();
|
||||
|
||||
// Act
|
||||
pool.ReleaseIP(ip1);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(253, pool.AvailableIPs);
|
||||
Assert.AreEqual(1, pool.UsedIPs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ReleaseIP_ThrowsOnUnusedIP()
|
||||
{
|
||||
// Arrange
|
||||
var pool = new IPPool("test-pool", "192.168.1.0/24");
|
||||
var ip = IPAddress.Parse("192.168.1.10");
|
||||
|
||||
// Act
|
||||
pool.ReleaseIP(ip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Clear_ClearsAllUsedIPs()
|
||||
{
|
||||
// Arrange
|
||||
var pool = new IPPool("test-pool", "192.168.1.0/24");
|
||||
pool.GetNextIP();
|
||||
pool.GetNextIP();
|
||||
|
||||
// Act
|
||||
pool.Clear();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(254, pool.AvailableIPs);
|
||||
Assert.AreEqual(0, pool.UsedIPs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PSProxmox.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PSProxmox.Tests.Models
|
||||
{
|
||||
[TestClass]
|
||||
public class ProxmoxVMBuilderTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_SetsName()
|
||||
{
|
||||
// Arrange
|
||||
string name = "test-vm";
|
||||
|
||||
// Act
|
||||
var builder = new ProxmoxVMBuilder(name);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(name, builder.Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Constructor_ThrowsOnNullName()
|
||||
{
|
||||
// Act
|
||||
var builder = new ProxmoxVMBuilder(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithVMID_SetsVMID()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
int vmid = 100;
|
||||
|
||||
// Act
|
||||
builder.WithVMID(vmid);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(vmid, builder.VMID);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithNode_SetsNode()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
string node = "pve1";
|
||||
|
||||
// Act
|
||||
builder.WithNode(node);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(node, builder.Node);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void WithNode_ThrowsOnNullNode()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
|
||||
// Act
|
||||
builder.WithNode(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithMemory_SetsMemory()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
int memory = 2048;
|
||||
|
||||
// Act
|
||||
builder.WithMemory(memory);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(memory, builder.Memory);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void WithMemory_ThrowsOnZeroMemory()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
|
||||
// Act
|
||||
builder.WithMemory(0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void WithMemory_ThrowsOnNegativeMemory()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
|
||||
// Act
|
||||
builder.WithMemory(-1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithCores_SetsCores()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
int cores = 4;
|
||||
|
||||
// Act
|
||||
builder.WithCores(cores);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(cores, builder.Cores);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void WithCores_ThrowsOnZeroCores()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
|
||||
// Act
|
||||
builder.WithCores(0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithDisk_AddsDisk()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
int sizeGB = 32;
|
||||
string storage = "local-lvm";
|
||||
|
||||
// Act
|
||||
builder.WithDisk(sizeGB, storage);
|
||||
var parameters = builder.Build();
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(parameters.ContainsKey("scsi0"));
|
||||
Assert.AreEqual($"{storage}:{sizeGB},format=raw", parameters["scsi0"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithNetwork_AddsNetwork()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
string model = "virtio";
|
||||
string bridge = "vmbr0";
|
||||
|
||||
// Act
|
||||
builder.WithNetwork(model, bridge);
|
||||
var parameters = builder.Build();
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(parameters.ContainsKey("net0"));
|
||||
Assert.AreEqual($"{model},bridge={bridge}", parameters["net0"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithIPConfig_AddsIPConfig()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm");
|
||||
string model = "virtio";
|
||||
string bridge = "vmbr0";
|
||||
string ipAddress = "192.168.1.10/24";
|
||||
string gateway = "192.168.1.1";
|
||||
|
||||
// Act
|
||||
builder.WithNetwork(model, bridge);
|
||||
builder.WithIPConfig(ipAddress, gateway);
|
||||
var parameters = builder.Build();
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(parameters.ContainsKey("net0"));
|
||||
Assert.AreEqual($"{model},bridge={bridge},ip={ipAddress},gw={gateway}", parameters["net0"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsCorrectParameters()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new ProxmoxVMBuilder("test-vm")
|
||||
.WithVMID(100)
|
||||
.WithNode("pve1")
|
||||
.WithMemory(2048)
|
||||
.WithCores(2)
|
||||
.WithDisk(32, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithIPConfig("192.168.1.10/24", "192.168.1.1")
|
||||
.WithBootOrder("disk", "net")
|
||||
.WithVGA("std");
|
||||
|
||||
// Act
|
||||
var parameters = builder.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("test-vm", parameters["name"]);
|
||||
Assert.AreEqual("100", parameters["vmid"]);
|
||||
Assert.AreEqual("2048", parameters["memory"]);
|
||||
Assert.AreEqual("2", parameters["cores"]);
|
||||
Assert.AreEqual("host", parameters["cpu"]);
|
||||
Assert.AreEqual("l26", parameters["ostype"]);
|
||||
Assert.AreEqual("local-lvm:32,format=raw", parameters["scsi0"]);
|
||||
Assert.AreEqual("virtio,bridge=vmbr0,ip=192.168.1.10/24,gw=192.168.1.1", parameters["net0"]);
|
||||
Assert.AreEqual("disk;net", parameters["boot"]);
|
||||
Assert.AreEqual("std", parameters["vga"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0" />
|
||||
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
|
||||
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PSProxmox.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user