Update Export-ZertoVpg.Tests.ps1
Complete creation of Function Unit Tests.
This commit is contained in:
@@ -48,14 +48,202 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg {
|
||||
$returnObj = @{
|
||||
VpgName = "HRIS"
|
||||
VpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"
|
||||
}
|
||||
return $returnObj
|
||||
}
|
||||
|
||||
$outputPath = "TestDrive:\"
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName New-ZertoVpgSettingsIdentifier {
|
||||
return "1024d377-afb8-4880-82f0-96eeff413ffd"
|
||||
}
|
||||
|
||||
it "Should Exist" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting {
|
||||
$returnObj = @{
|
||||
Backup = $null
|
||||
Basic = @{
|
||||
JournalHistoryInHours = 4
|
||||
Name = "HRIS"
|
||||
Priority = "Medium"
|
||||
ProtectedSiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
RecoverySiteIdentifier = "07f62976-6228-40ff-9542-4d7837114f37"
|
||||
RpoInSeconds = 300
|
||||
ServiceProfileIdentifier = $null
|
||||
TestIntervalInMinutes = 43200
|
||||
UseWanCompression = $true
|
||||
ZorgIdentifier = $null
|
||||
}
|
||||
BootGroups = @{
|
||||
BootGroups = @(
|
||||
@{
|
||||
BootDelayInSeconds = 0
|
||||
BootGroupIdentifier = "00000000-0000-0000-0000-000000000000"
|
||||
Name = "Default"
|
||||
}
|
||||
)
|
||||
}
|
||||
Journal = @{
|
||||
DatastoreIdentifier = $null
|
||||
Limitation = @{
|
||||
HardLimitInMB = 0
|
||||
HardLimitInPercent = 0
|
||||
WarningThresholdInMb = 0
|
||||
WarningThresholdInPercent = 0
|
||||
}
|
||||
}
|
||||
Networks = @{
|
||||
Failover = @{
|
||||
Hypervisor = @{
|
||||
DefaultNetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1"
|
||||
}
|
||||
VCD = $null
|
||||
}
|
||||
FailoverTest = @{
|
||||
Hypervisor = @{
|
||||
DefaultNetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1"
|
||||
}
|
||||
VCD = $null
|
||||
}
|
||||
}
|
||||
Protected = @{
|
||||
VCD = $null
|
||||
}
|
||||
Recovery = @{
|
||||
DefaultDatastoreClusterIdentifier = $null
|
||||
DefaultDatastoreIdentifier = $null
|
||||
DefaultFolderIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.vm"
|
||||
DefaultHostClusterIdentifier = $null
|
||||
DefaultHostIdentifier = $null
|
||||
ResourcePoolIdentifier = $null
|
||||
VCD = $null
|
||||
}
|
||||
Scripting = @{
|
||||
PostBackup = $null
|
||||
PostRecovey = @{
|
||||
Command = $null
|
||||
Parameters = $null
|
||||
TimeOutInSeconds = 300
|
||||
}
|
||||
PreRecovery = @{
|
||||
Command = $null
|
||||
Parameters = $null
|
||||
TimeOutInSeconds = 300
|
||||
}
|
||||
}
|
||||
Vms = @(
|
||||
@{
|
||||
BootGroupIdentifier = "00000000-0000-0000-0000-000000000000"
|
||||
Journal = @{
|
||||
DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02"
|
||||
Limitation = @{
|
||||
HardLimitInMB = 0
|
||||
HardLimitInPercent = 0
|
||||
WarningThresholdInMb = 0
|
||||
WarningThresholdInPercent = 0
|
||||
}
|
||||
}
|
||||
Nics = @(
|
||||
@{
|
||||
Failover = @{
|
||||
Hypervisor = @{
|
||||
DnsSuffix = $null
|
||||
IpConfig = $null
|
||||
NetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1"
|
||||
ShouldReplaceMacAddress = $false
|
||||
}
|
||||
VCD = $null
|
||||
}
|
||||
FailoverTest = @{
|
||||
Hypervisor = @{
|
||||
DnsSuffix = $null
|
||||
IpConfig = $null
|
||||
NetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1"
|
||||
ShouldReplaceMacAddress = $false
|
||||
}
|
||||
VCD = $null
|
||||
}
|
||||
NicIdentifier = "HRIS01-nic0"
|
||||
}
|
||||
)
|
||||
Recovery = @{
|
||||
DatastoreClusterIdentifier = $null
|
||||
DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02"
|
||||
FolderIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.vm"
|
||||
HostClusterIdentifier = $null
|
||||
HostIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.znest83esxus-0"
|
||||
ResourcePoolIdentifier = $null
|
||||
VCD = $null
|
||||
}
|
||||
VmIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.vm-28"
|
||||
Volumes = @(
|
||||
@{
|
||||
Datastore = @{
|
||||
DatastoreClusterIdentifier = $null
|
||||
DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02"
|
||||
IsThin = $true
|
||||
}
|
||||
IsSwap = $false
|
||||
Preseed = $null
|
||||
RDM = $null
|
||||
VCD = $null
|
||||
VolumeIdentifier = "scsi:0:0"
|
||||
},
|
||||
@{
|
||||
Datastore = @{
|
||||
DatastoreClusterIdentifier = $null
|
||||
DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02"
|
||||
IsThin = $true
|
||||
}
|
||||
IsSwap = $false
|
||||
Preseed = $null
|
||||
RDM = $null
|
||||
VCD = $null
|
||||
VolumeIdentifier = "scsi:0:1"
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
VpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"
|
||||
VpgSettingsIdentifier = "1024d377-afb8-4880-82f0-96eeff413ffd"
|
||||
}
|
||||
return $returnObj
|
||||
}
|
||||
|
||||
$outputPath = "TestDrive:"
|
||||
|
||||
it "Output path should exist" {
|
||||
$outputPath | Should -Exist
|
||||
}
|
||||
|
||||
it "Exported JSON file should exist after function called" {
|
||||
$vpgName = "HRIS"
|
||||
Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName
|
||||
$outputFile = "{0}\{1}.json" -f $outputPath, $vpgName
|
||||
$outputFile | Should -Exist
|
||||
$outputFile | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
it "Only one file should be present in the TestDrive" {
|
||||
(Get-ChildItem $outputPath).Count | Should -BeExactly 1
|
||||
}
|
||||
|
||||
it "Should be valid JSON" {
|
||||
$vpgName = "HRIS"
|
||||
Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName
|
||||
$outputFile = "{0}\{1}.json" -f $outputPath, $vpgName
|
||||
Get-Content -Path $outputFile -Raw | ConvertFrom-Json
|
||||
}
|
||||
|
||||
It "Should be able to export more than one VPG" {
|
||||
$vpgName = @("HRIS", "HRIS2")
|
||||
Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName
|
||||
(Get-ChildItem $outputPath).Count | Should -BeExactly 2
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName New-ZertoVpgSettingsIdentifier
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user