From bcc5c49b711c6e4cc8bb1443298c0695591dfb5f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 5 Jun 2019 14:18:16 -0400 Subject: [PATCH] Create Get-ZASite Function and Tests --- Tests/Public/Get-ZASite.Tests.ps1 | 19 +++++++++++++++++++ ZertoApiWrapper/Public/Get-ZASite.ps1 | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Tests/Public/Get-ZASite.Tests.ps1 create mode 100644 ZertoApiWrapper/Public/Get-ZASite.ps1 diff --git a/Tests/Public/Get-ZASite.Tests.ps1 b/Tests/Public/Get-ZASite.Tests.ps1 new file mode 100644 index 0000000..f5816b6 --- /dev/null +++ b/Tests/Public/Get-ZASite.Tests.ps1 @@ -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 + } +} diff --git a/ZertoApiWrapper/Public/Get-ZASite.ps1 b/ZertoApiWrapper/Public/Get-ZASite.ps1 new file mode 100644 index 0000000..dc2b66d --- /dev/null +++ b/ZertoApiWrapper/Public/Get-ZASite.ps1 @@ -0,0 +1,18 @@ +<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> +function Get-ZASite { + [cmdletbinding()] + param( + [Parameter( + HelpMessage = "The ZORG identifier by which to filter site list. If the ZORG identifier is omitted, a list of all sites is retrieved." + )] + [ValidateNotNullOrEmpty()] + [string]$zOrgIdentifier + ) + $uri = "monitoring/sites" + if ( -not [String]::IsNullorEmpty($zOrgIdentifier) ) { + $filterTable = @{"zOrgIdentifier" = $zOrgIdentifier } + $filterString = Get-ZertoApiFilter -filterTable $filterTable + $uri = "{0}{1}" -f $uri, $filterString + } + Invoke-ZARestRequest -uri $uri +}