Update function to global variable

This commit is contained in:
Wes Carroll
2019-07-14 20:36:32 -04:00
parent dd144d3c47
commit 235434fe20
5 changed files with 51 additions and 38 deletions
+9 -8
View File
@@ -1,16 +1,16 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
Context "$script:function::Parameter Unit Tests" {
Context "$global:function::Parameter Unit Tests" {
It "Has a mandatory string parameter for the target host" {
Get-Command $script:function | Should -HaveParameter TargetHost -Mandatory -Type String
Get-Command $global:function | Should -HaveParameter TargetHost -Mandatory -Type String
}
It "Will not take a non-ip address as a 'TargetHost'" {
@@ -40,8 +40,8 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
It "Supports 'SupportsShouldProcess'" {
Get-Command $script:function | Should -HaveParameter WhatIf
Get-Command $script:function | Should -HaveParameter Confirm
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\(.+\)'
}
@@ -67,4 +67,5 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 1
}
}
Remove-Variable -Name here -Scope Global
Remove-Variable -Name function -Scope Global
+12 -9
View File
@@ -1,10 +1,10 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
@@ -14,13 +14,13 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
return (Get-Content "$global:here\Mocks\VPGInfo.json" -Raw | ConvertFrom-Json)
}
Context "$($script:function)::Parameter Unit Tests" {
Context "$($global:function)::Parameter Unit Tests" {
It "Has a parameter for the VpgName that is Mandatory" {
Get-Command $script:function | Should -HaveParameter vpgName -Mandatory -Type String
Get-Command $global:function | Should -HaveParameter vpgName -Mandatory -Type String
}
It "Has a parameter for the CheckpointName that is Mandatory" {
Get-Command $script:function | Should -HaveParameter CheckpointName -Mandatory -Type String
Get-Command $global:function | Should -HaveParameter CheckpointName -Mandatory -Type String
}
It "Throws and error when an empty or null checkpointName is specified" {
@@ -34,14 +34,14 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
It "Does not support 'SupportsShouldProcess'" {
Get-Command $script:function | Should -Not -HaveParameter WhatIf
Get-Command $script:function | Should -Not -HaveParameter Confirm
Get-Command $global:function | Should -Not -HaveParameter WhatIf
Get-Command $global:function | Should -Not -HaveParameter Confirm
$script:ScriptBlock | Should -not -match 'SupportsShouldProcess'
$script:ScriptBlock | Should -not -match '\$PSCmdlet\.ShouldProcess\(.+\)'
}
}
Context "$($script:function)::Function Unit Tests" {
Context "$($global:function)::Function Unit Tests" {
It "should return a not null or empty string" {
$results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name"
@@ -58,3 +58,6 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg -Exactly 1
}
}
Remove-Variable -Name function -Scope Global
Remove-Variable -Name here -Scope Global
@@ -1,21 +1,21 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
Context "$($script:function)::Parameter Unit Tests" {
Context "$($global:function)::Parameter Unit Tests" {
It "Has a parameter for the Required Credentials that is Mandatory" {
Get-Command $script:function | Should -HaveParameter credential -Mandatory -Type PSCredential
Get-Command $global:function | Should -HaveParameter credential -Mandatory -Type PSCredential
}
}
Context "$($script:function)::Function Unit Tests" {
Context "$($global:function)::Function Unit Tests" {
InModuleScope -ModuleName ZertoApiWrapper {
Mock -CommandName Invoke-ZARestRequest {
@@ -70,3 +70,6 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
}
Remove-Variable -Name function -Scope Global
Remove-Variable -Name here -Scope Global
+13 -10
View File
@@ -1,16 +1,16 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
Context "$($script:function)::Parameter Unit Tests" {
Context "$($global:function)::Parameter Unit Tests" {
It "server vairable has a mandatory String parameter" {
Get-Command $script:function | Should -HaveParameter zertoserver -Mandatory -Type String
Get-Command $global:function | Should -HaveParameter zertoserver -Mandatory -Type String
}
It "server variable does not accecpt an empty or null input" {
@@ -19,9 +19,9 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
It "port variable has a non-mandatory String parameter" {
Get-Command $script:function | Should -HaveParameter zertoPort -Not -Mandatory
Get-Command $script:function | Should -HaveParameter zertoPort -Type String
Get-Command $script:function | Should -HaveParameter zertoPort -DefaultValue "9669"
Get-Command $global:function | Should -HaveParameter zertoPort -Not -Mandatory
Get-Command $global:function | Should -HaveParameter zertoPort -Type String
Get-Command $global:function | Should -HaveParameter zertoPort -DefaultValue "9669"
}
It "port variable does not accecpt an empty or null input" {
@@ -37,7 +37,7 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
It "has a mandatory PSCredential parameter for the credential vairable" {
Get-Command $script:function | Should -HaveParameter credential -Mandatory -Type PSCredential
Get-Command $global:function | Should -HaveParameter credential -Mandatory -Type PSCredential
}
It "should require a PSCredentialObject for the credentials" {
@@ -61,7 +61,7 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
return (Get-Content -Path "$global:here\Mocks\LocalSiteInfo.json" -Raw | ConvertFrom-Json)
}
Context "$($script:function)::InModuleScope Function Unit Tests" {
Context "$($global:function)::InModuleScope Function Unit Tests" {
BeforeAll {
$server = '192.168.1.100'
@@ -138,3 +138,6 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
}
}
Remove-Variable -Name function -Scope Global
Remove-Variable -Name here -Scope Global
@@ -1,19 +1,19 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
BeforeAll {
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
Context "$($script:function)::Parameter Unit Tests" {
Context "$($global:function)::Parameter Unit Tests" {
it "Does not take any parameters" {
(get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11
}
}
Context "$($script:function)::Function Unit Tests" {
Context "$($global:function)::Function Unit Tests" {
InModuleScope -ModuleName ZertoApiWrapper {
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
# Attempted to Mock this per the Mock Below and it blew up. Auth Headers Returns a Dictionary
@@ -38,3 +38,6 @@ Describe $script:function -Tag 'Unit', 'Source', 'Built' {
}
}
}
Remove-Variable -Name function -Scope Global
Remove-Variable -Name here -Scope Global