diff --git a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 index 50d2f9d..2fa2e2e 100644 --- a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 @@ -16,4 +16,29 @@ Describe $file.BaseName -Tag 'Unit' { $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) $errors | Should -HaveCount 0 } -} \ No newline at end of file + + 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 + } +} diff --git a/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 index 5f88c47..cbd5250 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 @@ -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" + } } } }