Update target host validation
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#Requires -Modules Pester
|
#Requires -Modules Pester
|
||||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
$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' {
|
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
@@ -14,7 +14,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ParameterTestCases = @(
|
$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 = 'targetPort'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||||
@{ParameterName = 'token'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
@{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 {
|
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||||
param($ParameterName, $Validation)
|
param($ParameterName, $Validation)
|
||||||
Switch ($Validation) {
|
Switch ($Validation) {
|
||||||
'Script' {
|
|
||||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
|
||||||
$attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1
|
|
||||||
}
|
|
||||||
|
|
||||||
'Range' {
|
'Range' {
|
||||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||||
@@ -63,8 +58,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
|||||||
It "Supports 'SupportsShouldProcess'" {
|
It "Supports 'SupportsShouldProcess'" {
|
||||||
Get-Command $global:function | Should -HaveParameter WhatIf
|
Get-Command $global:function | Should -HaveParameter WhatIf
|
||||||
Get-Command $global:function | Should -HaveParameter Confirm
|
Get-Command $global:function | Should -HaveParameter Confirm
|
||||||
$script:ScriptBlock | Should -match 'SupportsShouldProcess'
|
$script:ScriptBlock | Should -Match 'SupportsShouldProcess'
|
||||||
$script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
$script:ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ function Add-ZertoPeerSite {
|
|||||||
Mandatory,
|
Mandatory,
|
||||||
HelpMessage = "Target Hostname or IP address to pair the localsite to."
|
HelpMessage = "Target Hostname or IP address to pair the localsite to."
|
||||||
)]
|
)]
|
||||||
[ValidateScript( { $_ -match [IPAddress]$_ } )]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$targetHost,
|
[string]$targetHost,
|
||||||
[Parameter(
|
[Parameter(
|
||||||
HelpMessage = "Target communication port. Default is 9081"
|
HelpMessage = "Target communication port. Default is 9081"
|
||||||
|
|||||||
Reference in New Issue
Block a user