Create Get-ZAVpg Function and Tests

This commit is contained in:
Wes Carroll
2019-06-05 14:19:34 -04:00
parent 97aa9f1ba8
commit 87857303a0
2 changed files with 55 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
#Requires -Modules Pester
$moduleFileName = "ZertoApiWrapper.psd1"
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
$file = Get-ChildItem "$here\$sut"
$modulePath = $here -replace "Public", ""
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
Import-Module $moduleFile -Force
Describe $file.BaseName -Tag 'Unit' {
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
}
}
+36
View File
@@ -0,0 +1,36 @@
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
function Get-ZAVpg {
[cmdletbinding(DefaultParameterSetName = 'zOrg')]
param(
[Parameter(
HelpMessage = "The ZORG identifier by which to filter the VPG list. If the ZORG identifier is omitted, a list of all VPGs is retrieved.",
ParameterSetName = 'zOrg'
)]
[ValidateNotNullOrEmpty()]
[string]$zOrgIdentifier,
[Parameter(
HelpMessage = "The VPG Identifier",
ParameterSetName = "vpg",
Mandatory = $true
)]
[ValidateNotNullOrEmpty()]
[string]$vpgIdentifier
)
$uri = "monitoring/vpgs"
switch ($PSCmdlet.ParameterSetName) {
zOrg {
if ( -not [String]::IsNullorEmpty($zOrgIdentifier) ) {
$filterTable = @{"zOrgIdentifier" = $zOrgIdentifier }
$filterString = Get-ZertoApiFilter -filterTable $filterTable
$uri = "{0}{1}" -f $uri, $filterString
}
}
vpg {
$uri = "{0}/$vpgIdentifier"
}
}
Invoke-ZARestRequest -uri $uri
}