Clean Test Organization
This commit is contained in:
@@ -9,35 +9,18 @@ Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Context "Basic Features" {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest {
|
||||
return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
It "Is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
It "Is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
it "Has proper parameters defined" {
|
||||
it "Has a mandatory string parameter for the target host" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetHost -Mandatory -Type String
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -Not -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "Returns a string value" {
|
||||
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081'
|
||||
$results | should -Not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | Should -BeExactly "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
it "Will not take a non-int as a port" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null} | should -Throw
|
||||
}
|
||||
|
||||
it "Will not take a non-ip address as a 'TargetHost'" {
|
||||
@@ -47,8 +30,23 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
{Add-ZertoPeerSite -targetHost $null -targetPort '9081'} | should -Throw
|
||||
}
|
||||
|
||||
it "Will not require a target port to be defined" {
|
||||
Add-ZertoPeerSite -targetHost '192.168.1.100'
|
||||
it "Has a non-mandatory string parameter for the target port with default value of 9081" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -Type Int32
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -DefaultValue 9081
|
||||
}
|
||||
|
||||
it "Will not take a non-int as a port" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null} | should -Throw
|
||||
}
|
||||
|
||||
It "Will fail if the specified port is outside of the range 1024 - 65535" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1} | Should -Throw
|
||||
}
|
||||
|
||||
it "Supports 'SupportsShouldProcess'" {
|
||||
@@ -57,6 +55,20 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest {
|
||||
return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
it "Returns a string value" {
|
||||
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081'
|
||||
$results | should -Not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | Should -BeExactly "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
}
|
||||
|
||||
@@ -9,12 +9,7 @@ Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
return "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg {
|
||||
return @{vpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"}
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
@@ -22,38 +17,50 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
it "Has a parameter for the VpgName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory -Type String
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
return "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg {
|
||||
return @{vpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"}
|
||||
}
|
||||
|
||||
it "Has a parameter for the CheckpointName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter CheckpointName -Mandatory -Type String
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "Has a parameter for the VpgName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "Has a parameter for the CheckpointName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter CheckpointName -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "Throws and error when an empty or null checkpointName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null} | Should -Throw
|
||||
}
|
||||
|
||||
it "Throws an error when an empty or null vpgName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
}
|
||||
|
||||
it "Does not support 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter Confirm
|
||||
$file | Should -Not -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -Not -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
it "should return a not null or empty string" {
|
||||
$results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name"
|
||||
$results | should -not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | should -BeExactly "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
|
||||
it "Throws and error when an empty or null checkpointName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null} | Should -Throw
|
||||
}
|
||||
it "should return a not null or empty string" {
|
||||
$results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name"
|
||||
$results | should -not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | should -BeExactly "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
it "Throws an error when an empty or null vpgName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg
|
||||
}
|
||||
|
||||
it "Does not support 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter Confirm
|
||||
$file | Should -Not -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -Not -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg
|
||||
}
|
||||
@@ -14,44 +14,15 @@ $Server = "192.168.1.100"
|
||||
$zertoPort = "7669"
|
||||
|
||||
Describe $file.BaseName -Tag Unit {
|
||||
Context "Basic Features" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
$xZertoSession = @("7ecf544d-e7ed-4108-86f3-fb355c51cdfa")
|
||||
$Headers = @{'x-zerto-session' = $xZertoSession}
|
||||
$results = @{'Headers' = $Headers}
|
||||
return $results
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite {
|
||||
$results = @{
|
||||
BandwidthThrottlingInMBs = -1
|
||||
ContactEmail = "vSphere-Site01@zerto.com"
|
||||
ContactName = "vSphere-Site01@zerto.com"
|
||||
ContactPhone = "066-6666666"
|
||||
IpAddress = "192.168.200.1"
|
||||
IsReplicationToSelfEnabled = $True
|
||||
Link = @{
|
||||
href = "https://192.168.24.1:7669/v1/localsite"
|
||||
identifier = "928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
rel = $null
|
||||
type = "LocalSiteApi"
|
||||
}
|
||||
Location = "vSphere-Site01"
|
||||
SiteName = "vSphere-Site01 at Zerto"
|
||||
SiteType = "VCenter"
|
||||
UtcOffsetInMinutes = -240
|
||||
Version = "7.0.0"
|
||||
SiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
return $results
|
||||
}
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
it "server vairable has a mandatory String parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoserver -Mandatory -Type String
|
||||
@@ -76,56 +47,25 @@ Describe $file.BaseName -Tag Unit {
|
||||
it "port variable should fall between 1024 and 65535" {
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential} | Should -Throw
|
||||
}
|
||||
|
||||
it "has a mandatory PSCredential parameter for the credential vairable" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter credential -Mandatory -Type PSCredential
|
||||
}
|
||||
|
||||
it "returns null when -ReturnHeaders is not used" {
|
||||
Connect-ZertoServer -zertoServer $Server -zertoPort $zertoPort -credential $credential | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
$headers = Connect-ZertoServer -zertoServer $Server -zertoPort $zertoPort -credential $credential -returnHeaders
|
||||
it "returns a Hashtable with 2 keys" {
|
||||
$headers | Should -BeOfType Hashtable
|
||||
$headers.keys.count | should be 2
|
||||
}
|
||||
|
||||
it "return value has a key called 'x-zerto-session'" {
|
||||
$headers.ContainsKey('x-zerto-session') | should be $true
|
||||
}
|
||||
|
||||
it "return key 'x-zerto-session' value should be a string" {
|
||||
$headers['x-zerto-session'] | should -BeOfType "String"
|
||||
$headers['x-zerto-session'] | Should -BeExactly "7ecf544d-e7ed-4108-86f3-fb355c51cdfa"
|
||||
}
|
||||
|
||||
it "return value has a key called 'accept'" {
|
||||
$headers.ContainsKey('accept') | should be $true
|
||||
}
|
||||
|
||||
it "return key 'accept' value should be 'application/json'" {
|
||||
$headers['accept'] | should be 'application/json'
|
||||
}
|
||||
|
||||
it "should not require a port to be specified" {
|
||||
Connect-ZertoServer -zertoServer $Server -credential $credential
|
||||
}
|
||||
|
||||
it "should require a PSCredentialObject for the credentials" {
|
||||
{Connect-ZertoServer -zertoServer -credential "MyUsername"} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer -credential 1234} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString'})} | Should -Throw
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite
|
||||
}
|
||||
|
||||
InModuleScope ZertoApiWrapper {
|
||||
Context "InModuleScope Tests" {
|
||||
Context "$($file.BaseName)::InModuleScope Function Unit Tests" {
|
||||
|
||||
$server = '192.168.1.100'
|
||||
$userName = "zerto\build"
|
||||
$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password)
|
||||
@@ -163,11 +103,11 @@ Describe $file.BaseName -Tag Unit {
|
||||
}
|
||||
|
||||
$now = $(Get-Date).ticks
|
||||
Connect-ZertoServer -zertoServer '192.168.1.100' -credential $credential
|
||||
Connect-ZertoServer -zertoServer $server -credential $credential
|
||||
|
||||
it "Module Scope zvmServer variable tests" {
|
||||
$script:zvmServer | Should -Not -BeNullOrEmpty
|
||||
$script:zvmServer | Should -Be '192.168.1.100'
|
||||
$script:zvmServer | Should -Be $server
|
||||
}
|
||||
|
||||
it "Module Scope zvmPort variable tests" {
|
||||
@@ -198,6 +138,37 @@ Describe $file.BaseName -Tag Unit {
|
||||
$script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String
|
||||
}
|
||||
|
||||
$headers = Connect-ZertoServer -zertoServer $Server -credential $credential -returnHeaders
|
||||
it "returns a Hashtable with 2 keys" {
|
||||
$headers | Should -BeOfType Hashtable
|
||||
$headers.keys.count | should be 2
|
||||
}
|
||||
|
||||
it "return value has a key called 'x-zerto-session'" {
|
||||
$headers.ContainsKey('x-zerto-session') | should be $true
|
||||
}
|
||||
|
||||
it "return key 'x-zerto-session' value should be a string" {
|
||||
$headers['x-zerto-session'] | should -BeOfType "String"
|
||||
$headers['x-zerto-session'] | Should -BeExactly "7ecf544d-e7ed-4108-86f3-fb355c51cdfa"
|
||||
}
|
||||
|
||||
it "return value has a key called 'accept'" {
|
||||
$headers.ContainsKey('accept') | should be $true
|
||||
}
|
||||
|
||||
it "return key 'accept' value should be 'application/json'" {
|
||||
$headers['accept'] | should be 'application/json'
|
||||
}
|
||||
|
||||
it "should not require a port to be specified" {
|
||||
Connect-ZertoServer -zertoServer $Server -credential $credential
|
||||
}
|
||||
|
||||
it "returns null when -ReturnHeaders is not used" {
|
||||
Connect-ZertoServer -zertoServer $Server -credential $credential | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Remove-Variable {
|
||||
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
@@ -22,11 +23,15 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
it "Does not return anything" {
|
||||
Disconnect-ZertoServer | Should -BeNullOrEmpty
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "Does not take any parameters" {
|
||||
(get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11
|
||||
}
|
||||
}
|
||||
|
||||
it "Does not take any parameters" {
|
||||
(get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
it "Does not return anything" {
|
||||
Disconnect-ZertoServer | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
Context "$($File.BaseName)::Parameter Tests" {
|
||||
Context "$($File.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
It "has a mandatory String variable for the vraIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String
|
||||
@@ -108,7 +108,8 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
@{vraIpAddress = 192.168.1}, `
|
||||
@{vraIpAddress = 192.168.1.246}, `
|
||||
@{vraIpAddress = 32}, `
|
||||
@{vraIpAddress = ""}
|
||||
@{vraIpAddress = ""}, `
|
||||
@{vraIpAddress = $null}
|
||||
It "IpAddress field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw
|
||||
@@ -121,7 +122,8 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
@{subnetMask = 192.168.1}, `
|
||||
@{subnetMask = 192.168.1.246}, `
|
||||
@{subnetMask = 32}, `
|
||||
@{subnetMask = ""}
|
||||
@{subnetMask = ""}, `
|
||||
@{subnetMask = $null}
|
||||
It "subnetMask field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw
|
||||
@@ -134,7 +136,8 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
@{defaultGateway = 192.168.1}, `
|
||||
@{defaultGateway = 192.168.1.246}, `
|
||||
@{defaultGateway = 32}, `
|
||||
@{defaultGateway = ""}
|
||||
@{defaultGateway = ""}, `
|
||||
@{defaultGateway = $null}
|
||||
It "defaultGateway field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw
|
||||
@@ -142,12 +145,17 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
$cases = `
|
||||
@{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, `
|
||||
@{vraIdentifier = $null; paramName = "vraIdentifier"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = $null}
|
||||
|
||||
It "<paramName> does not take empty strings" -TestCases $cases {
|
||||
It "<paramName> does not take empty or null" -TestCases $cases {
|
||||
param($vraIdentifier, $paramValue, $paramName )
|
||||
if ([String]::IsNullOrEmpty($vraIdentifier)) {
|
||||
{Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw
|
||||
@@ -157,7 +165,7 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($File.BaseName)::Function Tests" {
|
||||
Context "$($File.BaseName)::Function Unit Tests" {
|
||||
|
||||
It "Returns a string" {
|
||||
$results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup"
|
||||
|
||||
@@ -19,29 +19,35 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
it "has a mantatory string parameter for the output path" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter outputPath -Type String -Mandatory
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "has a mantatory string parameter for the output path" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter outputPath -Type String -Mandatory
|
||||
}
|
||||
|
||||
it "has a non-mandatory string array parameter for vpgName(s) to export" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] -Mandatory
|
||||
}
|
||||
|
||||
it "has a non-mandatory switch parameter to export all vpgs" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter allVpgs -Type Switch -Mandatory
|
||||
}
|
||||
|
||||
it "No defined vpgName or AllVpg switch should throw an error" {
|
||||
{Export-ZertoVpg -outputPath "."} | Should -Throw
|
||||
}
|
||||
|
||||
it "Output path does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "" -allVpgs} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath $null -allVpgs} | Should -Throw
|
||||
}
|
||||
|
||||
it "Vpg Name parameter does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = ""} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = $null} | Should -Throw
|
||||
}
|
||||
}
|
||||
|
||||
it "has a non-mandatory string array parameter for vpgName(s) to export" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] -Mandatory
|
||||
}
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
|
||||
it "has a non-mandatory switch parameter to export all vpgs" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter allVpgs -Type Switch -Mandatory
|
||||
}
|
||||
|
||||
it "No defined vpgName or AllVpg switch should throw an error" {
|
||||
{Export-ZertoVpg -outputPath "."} | Should -Throw
|
||||
}
|
||||
|
||||
it "Output path does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "" -allVpgs} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath $null -allVpgs} | Should -Throw
|
||||
}
|
||||
|
||||
it "Vpg Name parameter does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = ""} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = $null} | Should -Throw
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user