Update Edit Vra Tests

This commit is contained in:
Wes Carroll
2019-03-31 16:37:02 -04:00
parent 5139f79366
commit 831e1562b5
2 changed files with 104 additions and 20 deletions
+103 -20
View File
@@ -1,6 +1,6 @@
#Requires -Modules Pester #Requires -Modules Pester
$moduleFileName = "ZertoApiWrapper.psd1" $moduleFileName = "ZertoApiWrapper.psd1"
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") $here = (Split-Path -Parent $MyInvocation.MyCommand.Path) -Replace "Tests", "ZertoApiWrapper"
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
$file = Get-ChildItem "$here\$sut" $file = Get-ChildItem "$here\$sut"
$modulePath = $here -replace "Public", "" $modulePath = $here -replace "Public", ""
@@ -15,7 +15,7 @@ Describe $file.BaseName -Tag 'Unit' {
} }
Mock -ModuleName ZertoApiWrapper Get-ZertoVra { Mock -ModuleName ZertoApiWrapper Get-ZertoVra {
vraInformation = @{ $vraInformation = @{
DatastoreClusterIdentifier = $null DatastoreClusterIdentifier = $null
DatastoreClusterName = $null DatastoreClusterName = $null
DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore" DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore"
@@ -60,6 +60,7 @@ Describe $file.BaseName -Tag 'Unit' {
} }
VraVersion = 7.0 VraVersion = 7.0
} }
return $vraInformation
} }
It "is valid Powershell (Has no script errors)" { It "is valid Powershell (Has no script errors)" {
@@ -69,28 +70,110 @@ Describe $file.BaseName -Tag 'Unit' {
$errors | Should -HaveCount 0 $errors | Should -HaveCount 0
} }
It "has a mandatory String variable for the vraIdentifier" { Context "$($File.BaseName)::Parameter Tests" {
Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String
{Edit-ZertoVra} It "has a mandatory String variable for the vraIdentifier" {
Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String
{Edit-ZertoVra}
}
It "has a non-mandatory String variable for the Bandwidth Group" {
Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter groupName -Type String
}
it "has a non-mandatory String variable for the staticIp Address" {
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String
}
it "has a non-mandatory String variable for the default gateway" {
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String
}
it "has a non-mandatory String variable for the subnetmask" {
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String
}
it "supports WhatIf" {
Get-Command $file.BaseName | Should -HaveParameter WhatIf -Not -Mandatory
}
$cases = `
@{vraIpAddress = "192.168.1.256"}, `
@{vraIpAddress = "192.168.1"}, `
@{vraIpAddress = "String"}, `
@{vraIpAddress = 192.168.1}, `
@{vraIpAddress = 192.168.1.246}, `
@{vraIpAddress = 32}, `
@{vraIpAddress = ""}
It "IpAddress field require valid IP addresses as a String" -TestCases $cases {
param ( $vraIpAddress )
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw
}
$cases = `
@{subnetMask = "192.168.1.256"}, `
@{subnetMask = "192.168.1"}, `
@{subnetMask = "String"}, `
@{subnetMask = 192.168.1}, `
@{subnetMask = 192.168.1.246}, `
@{subnetMask = 32}, `
@{subnetMask = ""}
It "subnetMask field require valid IP addresses as a String" -TestCases $cases {
param ( $vraIpAddress )
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw
}
$cases = `
@{defaultGateway = "192.168.1.256"}, `
@{defaultGateway = "192.168.1"}, `
@{defaultGateway = "String"}, `
@{defaultGateway = 192.168.1}, `
@{defaultGateway = 192.168.1.246}, `
@{defaultGateway = 32}, `
@{defaultGateway = ""}
It "defaultGateway field require valid IP addresses as a String" -TestCases $cases {
param ( $vraIpAddress )
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw
}
$cases = `
@{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, `
@{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, `
@{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, `
@{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, `
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}
It "<paramName> does not take empty strings" -TestCases $cases {
param($vraIdentifier, $paramValue, $paramName )
if ([String]::IsNullOrEmpty($vraIdentifier)) {
{Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw
} else {
{Edit-ZertoVra -vraIdentifier $vraIdentifier -$paramName $paramValue} | should -Throw
}
}
} }
It "has a non-mandatory String variable for the Bandwidth Group" { Context "$($File.BaseName)::Function Tests" {
Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter groupName -Type String
}
it "has a non-mandatory String variable for the staticIp Address" { It "Returns a string" {
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory $results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup"
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String $results | should not benullorempty
} $results | should -BeOfType "String"
$results | Should -BeExactly "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f"
}
it "has a non-mandatory String variable for the default gateway" { it "Supports 'SupportsShouldProcess'" {
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory Get-Command $file.BaseName | Should -HaveParameter WhatIf
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String Get-Command $file.BaseName | Should -HaveParameter Confirm
} $file | Should -FileContentMatch 'SupportsShouldProcess'
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
}
it "has a non-mandatory String variable for the default gateway" {
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String
} }
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra
} }
+1
View File
@@ -84,3 +84,4 @@ function Edit-ZertoVra {
# Nothing to Do # Nothing to Do
} }
} }
#TODO: Refactor