Updating Tests
This commit is contained in:
@@ -15,37 +15,45 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
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 "Should return a string value" {
|
||||
it "Has proper parameters defined" {
|
||||
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 "Should not take a non-int as a port" {
|
||||
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
|
||||
}
|
||||
|
||||
it "Should not take a non-ip address as a 'TargetHost'" {
|
||||
it "Will not take a non-ip address as a 'TargetHost'" {
|
||||
{Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081'} | should -Throw
|
||||
}
|
||||
|
||||
it "Should not require a target port to be defined" {
|
||||
it "Will not require a target port to be defined" {
|
||||
Add-ZertoPeerSite -targetHost '192.168.1.100'
|
||||
}
|
||||
|
||||
it "Should support '-whatif'" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -WhatIf} | Should -Not -Throw
|
||||
it "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -HaveParameter Confirm
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
|
||||
@@ -22,19 +22,34 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
it "should return a string" {
|
||||
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 "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 "should require a tag name" {
|
||||
it "Throws and error when an empty checkpointName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw
|
||||
}
|
||||
|
||||
it "should NOT support '-WhatIf'" {
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "Checkers" -whatif} | Should -Throw
|
||||
it "Throws an error when an empty vpgName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "" -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\(.+\)'
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
|
||||
@@ -29,6 +29,19 @@ Describe $file.BaseName -Tag Unit {
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
it "has a mandatory String parameter for the server vairable" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoserver -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "has a non-mandatory String parameter for the port variable" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoPort -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoPort -Type String
|
||||
}
|
||||
|
||||
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 $zertoServer -zertoPort $zertoPort -credential $credential | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
@@ -10,10 +10,87 @@ Import-Module $moduleFile -Force
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest {
|
||||
return "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Get-ZertoVra {
|
||||
vraInformation = @{
|
||||
DatastoreClusterIdentifier = $null
|
||||
DatastoreClusterName = $null
|
||||
DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore"
|
||||
DatastoreName = "Prod_Datastore"
|
||||
HostIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.znest82esxus-1"
|
||||
HostVersion = 6.5
|
||||
IpAddress = 192.168.1.100
|
||||
Link = @{
|
||||
href = "https://192.168.1.200:7669/v1/vras/2609816293328110468"
|
||||
identifier = "269816293328110468"
|
||||
rel = $null
|
||||
type = "VraApi"
|
||||
}
|
||||
MemoryInGB = 3
|
||||
NetworkIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.network-1"
|
||||
NetworkName = "Test Network"
|
||||
Progress = 0
|
||||
ProtectedCounters = @{
|
||||
Vms = 0
|
||||
Volumes = 0
|
||||
Vpgs = 0
|
||||
}
|
||||
RecoveryCounters = @{
|
||||
Vms = 0
|
||||
Volumes = 0
|
||||
Vpgs = 0
|
||||
}
|
||||
SelfProtectedVpgs = 0
|
||||
Status = 0
|
||||
VraAlerts = @{
|
||||
VraAlertStatus = 0
|
||||
}
|
||||
VraGroup = "default_group"
|
||||
VraIdentifier = 269816293328110468
|
||||
VraIdentifierStr = "269816293328110468"
|
||||
VraName = "VRA-znest82esxus-1"
|
||||
VraNetworkDataApi = @{
|
||||
DefaultGateway = "192.168.1.1"
|
||||
SubnetMask = "255.255.255.0"
|
||||
VraIpAddress = "192.168.1.100"
|
||||
VraIpConfigurationTypeApi = "Dhcp"
|
||||
}
|
||||
VraVersion = 7.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
|
||||
}
|
||||
|
||||
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 default gateway" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ function Checkpoint-ZertoVpg {
|
||||
Mandatory = $true,
|
||||
HelpMessage = "Name of the VPG to tag."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$vpgName,
|
||||
[Parameter(
|
||||
Mandatory = $true,
|
||||
|
||||
Reference in New Issue
Block a user