Update For Pester Tests

This commit is contained in:
Wes Carroll
2019-04-29 16:15:42 -04:00
parent 7c40401b1f
commit 23bc5dbe99
2 changed files with 35 additions and 8 deletions
@@ -16,4 +16,29 @@ Describe $file.BaseName -Tag 'Unit' {
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors | Should -HaveCount 0
}
}
Context "$($file.BaseName)::Parameter Unit Tests" {
it "Supports 'ShouldProcess'" {
Get-Command $file.BaseName | Should -HaveParameter WhatIf
Get-Command $file.BaseName | Should -HaveParameter Confirm
$file | Should -FileContentMatch 'SupportsShouldProcess'
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
}
it "has a mandatory string parameter for the vpgName" {
Get-Command $file.BaseName | Should -HaveParameter vpgName
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
}
it "has a switch parameter for reverse protection" {
Get-Command $file.BaseName | Should -HaveParameter reverseProtection
Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type switch
}
}
Context "$($file.BaseName)::Function Unit Tests" {
#TODO
}
}
@@ -1,6 +1,6 @@
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
function Invoke-ZertoFailoverCommit {
[cmdletbinding()]
[cmdletbinding( SupportsShouldProcess = $true )]
param(
[Parameter(
HelpMessage = "Name(s) of the VPG(s) to commit.",
@@ -16,21 +16,23 @@ function Invoke-ZertoFailoverCommit {
begin {
$baseUri = "vpgs"
if ( $reverseProtection ) {
$body = @{"IsReverseProtection" = $true}
} else {
$body = @{"IsReverseProtection" = $false}
}
}
process {
if ( $reverseProtection.IsPresent ) {
$body = @{"IsReverseProtection" = $true }
} else {
$body = @{"IsReverseProtection" = $false }
}
foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
if ( -not $vpgId ) {
Write-Error "VPG: $name could not be found. Please check the name and try again. Skipping."
} else {
$uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
if ($PSCmdlet.ShouldProcess($body, $uri)) {
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
}
}
}
}