Update target host validation

This commit is contained in:
Wes Carroll
2020-08-20 12:29:40 -04:00
parent cb528df3d4
commit ced5671ab2
2 changed files with 5 additions and 10 deletions
+4 -9
View File
@@ -1,6 +1,6 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $PSCommandPath)
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0]
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
@@ -14,7 +14,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
}
$ParameterTestCases = @(
@{ParameterName = 'targetHost'; Type = 'String'; Mandatory = $true; Validation = 'Script' }
@{ParameterName = 'targetHost'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
@{ParameterName = 'targetPort'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
@{ParameterName = 'token'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
)
@@ -27,11 +27,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
param($ParameterName, $Validation)
Switch ($Validation) {
'Script' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1
}
'Range' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
@@ -63,8 +58,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
It "Supports 'SupportsShouldProcess'" {
Get-Command $global:function | Should -HaveParameter WhatIf
Get-Command $global:function | Should -HaveParameter Confirm
$script:ScriptBlock | Should -match 'SupportsShouldProcess'
$script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
$script:ScriptBlock | Should -Match 'SupportsShouldProcess'
$script:ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)'
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ function Add-ZertoPeerSite {
Mandatory,
HelpMessage = "Target Hostname or IP address to pair the localsite to."
)]
[ValidateScript( { $_ -match [IPAddress]$_ } )]
[ValidateNotNullOrEmpty()]
[string]$targetHost,
[Parameter(
HelpMessage = "Target communication port. Default is 9081"