From 7f5fb6c1ac3a0155ce054a0d4f9f7caaec8978d4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 10 Jul 2019 21:10:13 -0400 Subject: [PATCH 01/89] Update Build Process Versions and Steps --- ZertoApiWrapper.Depend.psd1 | 6 +- ZertoApiWrapper.build.ps1 | 106 +++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/ZertoApiWrapper.Depend.psd1 b/ZertoApiWrapper.Depend.psd1 index 196f108..cb3f97d 100644 --- a/ZertoApiWrapper.Depend.psd1 +++ b/ZertoApiWrapper.Depend.psd1 @@ -7,7 +7,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '5.5.1' + Version = '5.5.2' Tags = 'Bootstrap' } @@ -19,7 +19,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '4.7.3' + Version = '4.8.1' Tags = 'Bootstrap' } @@ -31,7 +31,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '1.18.0' + Version = '1.18.1' Tags = 'Bootstrap' } diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index 1219dfd..96af513 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -2,8 +2,26 @@ $version = "{0}.{1}" -f $(Get-Content .\version.txt), $(Get-Date -format 'yyyyMMdd') +#Define the default task task . CreateArtifacts +#Region - Helper Functions +function ImportRawModule() { + If (Get-Module -Name ZertoApiWrapper) { + Remove-Module -Name ZertoApiWrapper -Force -ErrorAction Stop + } + Import-Module "$BuildRoot\ZertoApiWrapper\ZertoApiWrapper.psd1" -ErrorAction Stop +} + +function ImportBuiltModule() { + If (Get-Module -Name ZertoApiWrapper) { + Remove-Module -Name ZertoApiWrapper -Force -ErrorAction Stop + } + Import-Module "$BuildRoot\temp\ZertoApiWrapper.psd1" -ErrorAction Stop +} +#EndRegion + +#Region - Module Checks <# Synopsis: Ensure platyPS is installed #> task CheckPlatyPSInstalled { if ($null -eq (Get-Module -List platyPS)) { @@ -24,7 +42,9 @@ task CheckPSScriptAnalyzerInstalled { Install-Module -Scope CurrentUser -Repository PSGallery -Name PSScriptAnalyzer } } +#EndRegion +#Region - PSSA Tasks <# Synopsis: Analyze ZertoApiWrapper functions for Code Violations #> task AnalyzeSourceFiles CheckPSScriptAnalyzerInstalled, { $scriptAnalyzerParams = @{ @@ -56,14 +76,42 @@ task AnalyzeBuiltFiles CheckPSScriptAnalyzerInstalled, CreatePsm1ForRelease, { throw "One or more PSScriptAnalyzer errors/warnings were found" } } +#EndRegion -task FileTests CheckPesterInstalled, { - $testResultsFile = "$BuildRoot\Tests\TestResults.xml" +#Region - Clean Operations +task CleanTemp { + if (-not $(Test-Path "$BuildRoot\temp")) { + New-Item -Path $BuildRoot -Name "temp" -ItemType "Directory" + } + Remove-Item -Recurse -Path "$BuildRoot\temp\*" +} + +task CleanPublish { + if ($(Test-Path "$BuildRoot\publish")) { + Remove-Item -Recurse -Path "$BuildRoot\publish\*" + } +} +#EndRegion + +#Region - Pester Tests +task RawFileTests CheckPesterInstalled, { + ImportRawModule + $testResultsFile = "$BuildRoot\Tests\RawTestResults.xml" $script:results = Invoke-Pester -Script "$BuildRoot" -Tag Unit -OutputFile $testResultsFile -PassThru -Show Fails $FailureMessage = '{0} Unit test(s) failed. Aborting build' -f $results.FailedCount Assert ($results.FailedCount -eq 0) $FailureMessage } +task BuiltFileTests CheckPesterInstalled, { + ImportBuiltModule + $testResultsFile = "$BuildRoot\Tests\BuiltTestResults.xml" + $script:results = Invoke-Pester -Script "$BuildRoot" -Tag Unit -OutputFile $testResultsFile -PassThru -Show Fails + $FailureMessage = '{0} Unit test(s) failed. Aborting build' -f $results.FailedCount + Assert ($results.FailedCount -eq 0) $FailureMessage +} +#EndRegion + +#Region - Build Help System $buildMamlParams = @{ Inputs = { Get-ChildItem docs\*.md } Outputs = "$BuildRoot\temp\en-us\ZertoApiWrapper-help.xml" @@ -77,17 +125,12 @@ task BuildMamlHelp CheckPlatyPSInstalled, { } task UpdateMarkdownHelp CheckPlatyPSInstalled, { - Remove-Module ZertoApiWrapper -force -ErrorAction SilentlyContinue - Import-Module .\ZertoApiWrapper\ZertoApiWrapper.psm1 -Force - Update-MarkdownHelp -Path docs -AlphabeticParamsOrder -} - -task UpdateMarkdownHelpModule CheckPlatyPSInstalled, { - Remove-Module ZertoApiWrapper -force -ErrorAction SilentlyContinue - Import-Module .\ZertoApiWrapper\ZertoApiWrapper.psm1 -Force + ImportRawModule Update-MarkdownHelpModule -Path docs -AlphabeticParamsOrder } +#EndRegion +#Region - Build Module Files task CreatePsd1ForRelease CleanTemp, { $functionsToExport = Get-ChildItem -Path 'ZertoApiWrapper\Public\*.ps1' | ForEach-Object { $_.BaseName } $releaseNotes = "# {0}{1}" -f $version, $(Get-Content .\RELEASENOTES.md -Raw) @@ -114,20 +157,14 @@ task CreatePsd1ForRelease CleanTemp, { New-ModuleManifest @ManifestParams } -task CleanTemp { - if (-not $(Test-Path "$BuildRoot\temp")) { - New-Item -Path $BuildRoot -Name "temp" -ItemType "Directory" - } - Remove-Item -Recurse -Path "$BuildRoot\temp\*" -} - task CreatePsm1ForRelease CreatePsd1ForRelease, { $emptyLine = "" $psm1Path = "$BuildRoot\temp\ZertoApiWrapper.psm1" $lines = '#------------------------------------------------------------#' - $Public = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Public\*.ps1 -ErrorAction SilentlyContinue ) - $functionCount = 0 - $exportString = "" + $Private = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Private\*.ps1 -ErrorAction Stop ) + $Public = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Public\*.ps1 -ErrorAction Stop ) + <# $functionCount = 0 + $exportString = "" foreach ($file in $Public) { if ($functionCount -eq 0) { $functionCount++ @@ -136,8 +173,7 @@ task CreatePsm1ForRelease CreatePsd1ForRelease, { $functionCount++ $exportString = "{0}, {1}" -f $exportString, $file.BaseName } - } - $Private = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Private\*.ps1 -ErrorAction SilentlyContinue ) + } #> Add-Content -Path $psm1Path -Value $lines Add-Content -Path $psm1Path -Value "#---------------------Private Functions----------------------#" Add-Content -Path $psm1Path -Value $lines @@ -154,27 +190,23 @@ task CreatePsm1ForRelease CreatePsd1ForRelease, { Add-Content -Path $psm1Path -Value $(Get-Content -Path $file.Fullname -Raw) Add-Content -Path $psm1Path -Value $emptyLine } - Add-Content -Path $psm1Path -Value $emptyLine - Add-Content -Path $psm1Path -Value "Export-ModuleMember -Function $exportString" + # Add-Content -Path $psm1Path -Value $emptyLine + # Add-Content -Path $psm1Path -Value "Export-ModuleMember -Function $exportString" } +#EndRegion -task CreateArtifacts CleanPublish, CreateModule, { +#Region - Artifacts \ Publish +# Full Build Process - No Publishing +task CreateArtifacts CleanPublish, CleanTemp, AnalyzeSourceFiles, RawFileTests, AnalyzeBuiltFiles, BuiltFileTests, BuildMamlHelp, { if (-not $(Test-Path "$BuildRoot\publish")) { New-Item -Path $BuildRoot -Name "publish" -ItemType Directory } Compress-Archive -Path .\temp\* -DestinationPath .\publish\ZertoApiWrapper.zip - Get-Module -Name ZertoApiWrapper | Remove-Module -Force - Import-Module .\temp\ZertoApiWrapper.psd1 -Force + ImportBuiltModule (Get-Module ZertoApiWrapper).ReleaseNotes | Add-Content .\publish\release-notes.txt (Get-Module ZertoApiWrapper).Version.ToString() | Add-Content .\publish\release-version.txt + Copy-Item "$BuildRoot\ZertoApiWrapper.build.ps1" "$BuildRoot\publish\ZertoApiWrapper.build.ps1" + Copy-Item "$BuildRoot\ZertoApiWrapper.Depend.psd1" "$BuildRoot\publish\ZertoApiWrapper.Depend.psd1" + Copy-Item "$BuildRoot\build.ps1" "$BuildRoot\publish\build.ps1" } - -task CleanPublish { - if ($(Test-Path "$BuildRoot\publish")) { - Remove-Item -Recurse -Path "$BuildRoot\publish\*" - } -} - -task CreateModule CleanTemp, FileTests, AnalyzeBuiltFiles, BuildMamlHelp, { - -} +#EndRegion From 7339366f7d8aeb4426c8036b757630a5ed4ee8df Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 10 Jul 2019 21:19:48 -0400 Subject: [PATCH 02/89] Update Build Pipeline for Additional Tests --- azure-pipelines.yml | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e1f7ae8..de9b562 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,10 +32,18 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/TestResults.xml' - testRunTitle: 'PS_Win2016' + testResultsFiles: '**/RawTestResults.xml' + testRunTitle: 'PS_Win2016_Raw' displayName: 'Publish Test Results' condition: always() + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/BuiltTestResults.xml' + testRunTitle: 'PS_Win2016_Built' + displayName: 'Publish Test Results' + condition: always() + # Windows PowerShell Core Build Job - job: Build_PSCore_Win2016 @@ -52,8 +60,15 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/TestResults.xml' - testRunTitle: 'PS_Win2016' + testResultsFiles: '**/RawTestResults.xml' + testRunTitle: 'PSCore_Win2016_Raw' + displayName: 'Publish Test Results' + condition: always() + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/BuiltTestResults.xml' + testRunTitle: 'PSCore_Win2016_Built' displayName: 'Publish Test Results' condition: always() @@ -72,8 +87,15 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/TestResults.xml' - testRunTitle: 'PSCore_Ubuntu1604' + testResultsFiles: '**/RawTestResults.xml' + testRunTitle: 'PSCore_Ubuntu_Raw' + displayName: 'Publish Test Results' + condition: always() + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/BuiltTestResults.xml' + testRunTitle: 'PSCore_Ubuntu_Built' displayName: 'Publish Test Results' condition: always() - task: PublishPipelineArtifact@0 @@ -104,7 +126,14 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/TestResults.xml' - testRunTitle: 'PSCore_MacOS1013' + testResultsFiles: '**/RawTestResults.xml' + testRunTitle: 'PSCore_MacOS1013_Raw' + displayName: 'Publish Test Results' + condition: always() + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/BuiltTestResults.xml' + testRunTitle: 'PSCore_MacOS1013_Built' displayName: 'Publish Test Results' condition: always() From 9a010244b492e6feeb7aad5402d997f441738e46 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 11 Jul 2019 07:55:47 -0400 Subject: [PATCH 03/89] Update to paths --- ZertoApiWrapper.build.ps1 | 12 ++++++------ azure-pipelines.yml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index 96af513..b823443 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -6,7 +6,7 @@ $version = "{0}.{1}" -f $(Get-Content .\version.txt), $(Get-Date -format 'yyyyMM task . CreateArtifacts #Region - Helper Functions -function ImportRawModule() { +function ImportSourceModule() { If (Get-Module -Name ZertoApiWrapper) { Remove-Module -Name ZertoApiWrapper -Force -ErrorAction Stop } @@ -94,9 +94,9 @@ task CleanPublish { #EndRegion #Region - Pester Tests -task RawFileTests CheckPesterInstalled, { - ImportRawModule - $testResultsFile = "$BuildRoot\Tests\RawTestResults.xml" +task SourceFileTests CheckPesterInstalled, { + ImportSourceModule + $testResultsFile = "$BuildRoot\Tests\SourceTestResults.xml" $script:results = Invoke-Pester -Script "$BuildRoot" -Tag Unit -OutputFile $testResultsFile -PassThru -Show Fails $FailureMessage = '{0} Unit test(s) failed. Aborting build' -f $results.FailedCount Assert ($results.FailedCount -eq 0) $FailureMessage @@ -125,7 +125,7 @@ task BuildMamlHelp CheckPlatyPSInstalled, { } task UpdateMarkdownHelp CheckPlatyPSInstalled, { - ImportRawModule + ImportSourceModule Update-MarkdownHelpModule -Path docs -AlphabeticParamsOrder } #EndRegion @@ -197,7 +197,7 @@ task CreatePsm1ForRelease CreatePsd1ForRelease, { #Region - Artifacts \ Publish # Full Build Process - No Publishing -task CreateArtifacts CleanPublish, CleanTemp, AnalyzeSourceFiles, RawFileTests, AnalyzeBuiltFiles, BuiltFileTests, BuildMamlHelp, { +task CreateArtifacts CleanPublish, CleanTemp, AnalyzeSourceFiles, SourceFileTests, AnalyzeBuiltFiles, BuiltFileTests, BuildMamlHelp, { if (-not $(Test-Path "$BuildRoot\publish")) { New-Item -Path $BuildRoot -Name "publish" -ItemType Directory } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index de9b562..9a6cd9e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,8 +32,8 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/RawTestResults.xml' - testRunTitle: 'PS_Win2016_Raw' + testResultsFiles: '**/SourceTestResults.xml' + testRunTitle: 'PS_Win2016_Source' displayName: 'Publish Test Results' condition: always() - task: PublishTestResults@2 @@ -60,8 +60,8 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/RawTestResults.xml' - testRunTitle: 'PSCore_Win2016_Raw' + testResultsFiles: '**/SourceTestResults.xml' + testRunTitle: 'PSCore_Win2016_Source' displayName: 'Publish Test Results' condition: always() - task: PublishTestResults@2 @@ -87,8 +87,8 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/RawTestResults.xml' - testRunTitle: 'PSCore_Ubuntu_Raw' + testResultsFiles: '**/SourceTestResults.xml' + testRunTitle: 'PSCore_Ubuntu_Source' displayName: 'Publish Test Results' condition: always() - task: PublishTestResults@2 @@ -126,8 +126,8 @@ jobs: - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/RawTestResults.xml' - testRunTitle: 'PSCore_MacOS1013_Raw' + testResultsFiles: '**/SourceTestResults.xml' + testRunTitle: 'PSCore_MacOS1013_Source' displayName: 'Publish Test Results' condition: always() - task: PublishTestResults@2 From e930f996d656c515de848e50ac114a7c5b6939fb Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 11 Jul 2019 18:05:53 -0400 Subject: [PATCH 04/89] Add mock files for testing --- Tests/Public/Mocks/AuthHeaders.json | 23 ++++++++ Tests/Public/Mocks/LocalSiteInfo.json | 20 +++++++ Tests/Public/Mocks/TaskId.txt | 1 + Tests/Public/Mocks/VPGInfo.json | 75 +++++++++++++++++++++++++++ Tests/Public/Mocks/ZAToken.json | 4 ++ 5 files changed, 123 insertions(+) create mode 100644 Tests/Public/Mocks/AuthHeaders.json create mode 100644 Tests/Public/Mocks/LocalSiteInfo.json create mode 100644 Tests/Public/Mocks/TaskId.txt create mode 100644 Tests/Public/Mocks/VPGInfo.json create mode 100644 Tests/Public/Mocks/ZAToken.json diff --git a/Tests/Public/Mocks/AuthHeaders.json b/Tests/Public/Mocks/AuthHeaders.json new file mode 100644 index 0000000..6f904f8 --- /dev/null +++ b/Tests/Public/Mocks/AuthHeaders.json @@ -0,0 +1,23 @@ +{ + "apiRequestResults": "", + "Headers": { + "Cache-Control": [ + "no-cache" + ], + "Server": [ + "Microsoft-HTTPAPI/2.0" + ], + "x-zerto-session": [ + "e34da0b0-4bc2-4cda-b316-0384e35bdca5" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Thu, 11 Jul 2019 19:05:40 GMT" + ], + "Content-Length": [ + "0" + ] + } +} diff --git a/Tests/Public/Mocks/LocalSiteInfo.json b/Tests/Public/Mocks/LocalSiteInfo.json new file mode 100644 index 0000000..8fe97a2 --- /dev/null +++ b/Tests/Public/Mocks/LocalSiteInfo.json @@ -0,0 +1,20 @@ +{ + "BandwidthThrottlingInMBs": -1, + "ContactEmail": "vSphere-Site01@zerto.com", + "ContactName": "vSphere-Site01@zerto.com", + "ContactPhone": "066-6666666", + "IpAddress": "192.168.200.1", + "IsReplicationToSelfEnabled": true, + "Link": { + "href": "https://192.168.222.1:7669/v1/localsite", + "identifier": "63a62dc2-ef6f-45aa-809f-9dbaeb8c06cf", + "rel": null, + "type": "LocalSiteApi" + }, + "Location": "vSphere-Site01", + "SiteIdentifier": "63a62dc2-ef6f-45aa-809f-9dbaeb8c06cf", + "SiteName": "vSphere-Site01 at Zerto", + "SiteType": "VCenter", + "UtcOffsetInMinutes": -240, + "Version": "7.0.0" +} diff --git a/Tests/Public/Mocks/TaskId.txt b/Tests/Public/Mocks/TaskId.txt new file mode 100644 index 0000000..6c7b99c --- /dev/null +++ b/Tests/Public/Mocks/TaskId.txt @@ -0,0 +1 @@ +7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a diff --git a/Tests/Public/Mocks/VPGInfo.json b/Tests/Public/Mocks/VPGInfo.json new file mode 100644 index 0000000..f2fae5e --- /dev/null +++ b/Tests/Public/Mocks/VPGInfo.json @@ -0,0 +1,75 @@ +{ + "ActiveProcessesApi": { + "RunningFailOverTestApi": null + }, + "ActualRPO": 6, + "BackupEnabled": false, + "ConfiguredRpoSeconds": 300, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "FailSafeHistory": { + "ActualFailSafeHistory": 60, + "ConfiguredFailSafeHistory": 60, + "FailSafeDescription": "" + }, + "HistoryStatusApi": { + "ActualHistoryInMinutes": 225, + "ConfiguredHistoryInMinutes": 60, + "EarliestCheckpoint": { + "CheckpointIdentifier": "166834", + "Tag": null, + "TimeStamp": "2019-07-11T13:47:23Z" + } + }, + "IOPs": 8, + "LastTest": "2019-07-11T16:51:07.022Z", + "Link": { + "href": "https://192.168.222.1:7669/v1/vpgs/99c460c1-a4ec-48dd-8921-bbcca9cd29b9", + "identifier": "99c460c1-a4ec-48dd-8921-bbcca9cd29b9", + "rel": null, + "type": "VpgApi" + }, + "Link_{0}": { + "href": "https://192.168.222.1:7669/v1/vpgs/99c460c1-a4ec-48dd-8921-bbcca9cd29b9", + "rel": "self", + "type": "VpgApi" + }, + "OrganizationName": "", + "Priority": 1, + "ProgressPercentage": 0, + "ProtectedSite": { + "href": "https://192.168.222.1:7669/v1/localsite", + "identifier": "63a62dc2-ef6f-45aa-809f-9dbaeb8c06cf", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 400, + "RecoverySite": { + "href": "https://192.168.222.1:7669/v1/peersites/3e4cdd0d-1064-4022-921f-6265ad6d335a", + "identifier": "3e4cdd0d-1064-4022-921f-6265ad6d335a", + "rel": null, + "type": "PeerSiteApi" + }, + "ServiceProfile": null, + "ServiceProfileIdentifier": null, + "ServiceProfileName": "", + "SourceSite": "vSphere-Site01 at Zerto", + "Status": 1, + "SubStatus": 0, + "TargetSite": "vSphere-Site02 at Zerto", + "ThroughputInMB": 58.55859375, + "UsedStorageInMB": 400, + "VmsCount": 4, + "VpgIdentifier": "99c460c1-a4ec-48dd-8921-bbcca9cd29b9", + "VpgName": "Exchange", + "Zorg": { + "href": "https://192.168.222.1:7669/v1/zorgs/00000000-0000-0000-0000-000000000000", + "identifier": "00000000-0000-0000-0000-000000000000", + "rel": null, + "type": "ZorgApi" + } +} diff --git a/Tests/Public/Mocks/ZAToken.json b/Tests/Public/Mocks/ZAToken.json new file mode 100644 index 0000000..335aa89 --- /dev/null +++ b/Tests/Public/Mocks/ZAToken.json @@ -0,0 +1,4 @@ +{ + "type": "Bearer", + "token": "N074r34l70k3n" +} From 5eae4857cf3b854805c5e73bcf74491a8e6d26fa Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 11 Jul 2019 18:14:32 -0400 Subject: [PATCH 05/89] Updating tests for multiuse --- Tests/Public/Add-ZertoPeerSite.Tests.ps1 | 92 ++++---- Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 | 78 +++---- Tests/Public/Connect-ZertoAnalytics.Tests.ps1 | 85 ++++++-- Tests/Public/Connect-ZertoServer.Tests.ps1 | 205 ++++++------------ Tests/Public/Disconnect-ZertoServer.Tests.ps1 | 53 ++--- 5 files changed, 247 insertions(+), 266 deletions(-) diff --git a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 index a55ee59..39fd439 100644 --- a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 @@ -1,76 +1,70 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 +Describe $script:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $script:function).ScriptBlock } - Context "$($file.BaseName)::Parameter Unit Tests" { + Context "$script:function::Parameter Unit Tests" { - it "Has a mandatory string parameter for the target host" { - Get-Command $file.BaseName | Should -HaveParameter TargetHost -Mandatory -Type String + It "Has a mandatory string parameter for the target host" { + Get-Command $script:function | Should -HaveParameter TargetHost -Mandatory -Type String } - it "Will not take a non-ip address as a 'TargetHost'" { - {Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081'} | should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081'} | should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081'} | should -Throw - {Add-ZertoPeerSite -targetHost $null -targetPort '9081'} | should -Throw + It "Will not take a non-ip address as a 'TargetHost'" { + { Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081' } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081' } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081' } | Should -Throw + { Add-ZertoPeerSite -targetHost $null -targetPort '9081' } | Should -Throw } - it "Has a non-mandatory string parameter for the target port with default value of 9081" { - Get-Command $file.BaseName | Should -HaveParameter TargetPort -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter TargetPort -Type Int32 - Get-Command $file.BaseName | Should -HaveParameter TargetPort -DefaultValue 9081 + It "Has a non-mandatory string parameter for the target port with default value of 9081" { + Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -Not -Mandatory + Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -Type Int32 + Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -DefaultValue 9081 } - it "Will not take a non-int as a port" { - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string'} | should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true} | should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null} | should -Throw + It "Will not take a non-int as a port" { + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string' } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null } | Should -Throw } It "Will fail if the specified port is outside of the range 1024 - 65535" { - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023} | Should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536} | Should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0} | Should -Throw - {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1} | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023 } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536 } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0 } | Should -Throw + { Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1 } | Should -Throw } - it "Supports 'SupportsShouldProcess'" { - Get-Command $file.BaseName | Should -HaveParameter WhatIf - Get-Command $file.BaseName | Should -HaveParameter Confirm - $file | Should -FileContentMatch 'SupportsShouldProcess' - $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + It "Supports 'SupportsShouldProcess'" { + Get-Command $script:function | Should -HaveParameter WhatIf + Get-Command $script:function | Should -HaveParameter Confirm + $script:ScriptBlock | Should -match 'SupportsShouldProcess' + $script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' } } - Context "$($file.BaseName)::Function Unit Tests" { - - Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest { - return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f" + Context "Add-ZertoPeerSite::Functional Unit Tests" { + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { + return (Get-Content "$global:here\Mocks\TaskId.txt") } - it "Returns a string value" { + It "Returns a string value" { $results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' - $results | should -Not -BeNullOrEmpty - $results | should -BeOfType "String" - $results | Should -BeExactly "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f" + $results | Should -Not -BeNullOrEmpty + $results | Should -BeOfType "String" + $results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" } - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + It "Does not return a taskId if '-whatif' is used" { + $results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -WhatIf + $results | Should -BeNullOrEmpty + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 1 } } diff --git a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 index f07f347..3cc79e4 100644 --- a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 @@ -1,66 +1,60 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 +Describe $script:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $script:function).ScriptBlock } Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { - return "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f" + return (Get-Content "$global:here\Mocks\TaskId.txt") } - Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg { - return @{vpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"} + Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg -ParameterFilter { $VpgName -eq "MyVpg" } { + return (Get-Content "$global:here\Mocks\VPGInfo.json" -Raw | ConvertFrom-Json) } - Context "$($file.BaseName)::Parameter Unit Tests" { - it "Has a parameter for the VpgName that is Mandatory" { - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory -Type String + Context "$($script:function)::Parameter Unit Tests" { + It "Has a parameter for the VpgName that is Mandatory" { + Get-Command $script:function | Should -HaveParameter vpgName -Mandatory -Type String } - it "Has a parameter for the CheckpointName that is Mandatory" { - Get-Command $file.BaseName | Should -HaveParameter CheckpointName -Mandatory -Type String + It "Has a parameter for the CheckpointName that is Mandatory" { + Get-Command $script:function | Should -HaveParameter CheckpointName -Mandatory -Type String } - it "Throws and error when an empty or null checkpointName is specified" { - {Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw - {Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null} | Should -Throw + It "Throws and error when an empty or null checkpointName is specified" { + { Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "" } | Should -Throw + { Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null } | Should -Throw } - it "Throws an error when an empty or null vpgName is specified" { - {Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint"} | Should -Throw - {Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint"} | Should -Throw + It "Throws an error when an empty or null vpgName is specified" { + { Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint" } | Should -Throw + { Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint" } | Should -Throw } - it "Does not support 'SupportsShouldProcess'" { - Get-Command $file.BaseName | Should -Not -HaveParameter WhatIf - Get-Command $file.BaseName | Should -Not -HaveParameter Confirm - $file | Should -Not -FileContentMatch 'SupportsShouldProcess' - $file | Should -Not -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + It "Does not support 'SupportsShouldProcess'" { + Get-Command $script:function | Should -Not -HaveParameter WhatIf + Get-Command $script:function | Should -Not -HaveParameter Confirm + $script:ScriptBlock | Should -not -match 'SupportsShouldProcess' + $script:ScriptBlock | Should -not -match '\$PSCmdlet\.ShouldProcess\(.+\)' } } - Context "$($file.BaseName)::Function Unit Tests" { + Context "$($script:function)::Function Unit Tests" { - it "should return a not null or empty string" { + It "should return a not null or empty string" { $results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name" - $results | should -not -BeNullOrEmpty - $results | should -BeOfType "String" - $results | should -BeExactly "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f" + $results | Should -not -BeNullOrEmpty + $results | Should -BeOfType "String" + $results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" + } + It "does not return anything when a invalid VPG is defined" { + $results = Checkpoint-ZertoVpg -vpgName "DoesNotExist" -checkpointName "My Checkpoint Name" + $results | Should -Be "Cannot find VPG named DoesNotExist. Please check the name and try again." } - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 2 + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg -Exactly 1 } -} \ No newline at end of file +} diff --git a/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 b/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 index 50d2f9d..fcfd65a 100644 --- a/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 +++ b/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 @@ -1,19 +1,72 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 +Describe $script:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $script:function).ScriptBlock } -} \ No newline at end of file + + Context "$($script: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 + } + } + + + + Context "$($script:function)::Function Unit Tests" { + + InModuleScope -ModuleName ZertoApiWrapper { + Mock -CommandName Invoke-ZARestRequest { + return (Get-Content "$global:here\Mocks\ZAToken.json"-Raw | ConvertFrom-Json) + } + + $password = 'NotARealPassword' | ConvertTo-SecureString -AsPlainText -Force + $cred = New-Object pscredential('NotARealUser', $password) + + $results = Connect-ZertoAnalytics -credential $cred + + It "Creates a Script Level Hashtable Variable for the ZertoAnalytics Headers" { + $script:zaHeaders | Should -BeOfType Hashtable + } + + It "the ZertoAnalytics Headers variable contains 2 items" { + $script:zaHeaders.keys | Should -HaveCount 2 + } + + It "the ZertoAnalytics Headers variable has an 'Accept' key" { + $script:zaHeaders.keys | Should -Contain 'Accept' + } + + It "thh ZertoAnalytics headers variable 'Accept' key should be JSON" { + $script:zaHeaders['Accept'] | Should -match 'application/json' + } + + It "the ZertoAnalytics Headers variable has an 'Authorization' key" { + $script:zaHeaders.keys | Should -Contain 'Authorization' + } + + It "the ZertoAnalytics Headers variable 'Authorization' key should start with 'Bearer'" { + $script:zaHeaders['Authorization'] | Should -Match '^Bearer ' + } + + It "Creates a Script Level Variable for the LastActionTime" { + $script:zaLastActionTime | Should -BeOfType Long + } + + It "LastActionTime Variable should be in the past" { + $script:zaLastActionTime | Should -BeLessThan (Get-Date).Ticks + } + + It "Returns Header Information" { + $results | Should -not -BeNullOrEmpty + $results['Authorization'] | Should -MatchExactly 'Bearer N074r34l70k3n' + $results['Accept'] | Should -Match 'application/json' + } + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZARestRequest -Exactly 1 + } + +} diff --git a/Tests/Public/Connect-ZertoServer.Tests.ps1 b/Tests/Public/Connect-ZertoServer.Tests.ps1 index 59c5e8b..de54536 100644 --- a/Tests/Public/Connect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Connect-ZertoServer.Tests.ps1 @@ -1,128 +1,94 @@ #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 -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) -$Server = "192.168.1.100" -$zertoPort = "7669" +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 +Describe $script:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $script:function).ScriptBlock } - Context "$($file.BaseName)::Parameter Unit Tests" { + Context "$($script:function)::Parameter Unit Tests" { - it "server vairable has a mandatory String parameter" { - Get-Command $file.BaseName | Should -HaveParameter zertoserver -Mandatory -Type String + It "server vairable has a mandatory String parameter" { + Get-Command $script:function | Should -HaveParameter zertoserver -Mandatory -Type String } - it "server variable does not accecpt an empty or null input" { - {Connect-ZertoServer -zertoServer $null -credential $credential} | Should -Throw - {Connect-ZertoServer -zertoServer "" -credential $credential} | Should -Throw + It "server variable does not accecpt an empty or null input" { + { Connect-ZertoServer -zertoServer $null -credential $credential } | Should -Throw + { Connect-ZertoServer -zertoServer "" -credential $credential } | Should -Throw } - it "port variable has a non-mandatory String parameter" { - Get-Command $file.BaseName | Should -HaveParameter zertoPort -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter zertoPort -Type String - Get-Command $file.BaseName | Should -HaveParameter zertoPort -DefaultValue "9669" + 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" } - it "port variable does not accecpt an empty or null input" { - {Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort "" -credential $credential} | Should -Throw - {Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort $null -credential $credential} | Should -Throw + It "port variable does not accecpt an empty or null input" { + { Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort "" -credential $credential } | Should -Throw + { Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort $null -credential $credential } | Should -Throw } - it "port variable should fall between 1024 and 65535" { - {Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential} | Should -Throw - {Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential} | Should -Throw - {Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential} | Should -Throw - {Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential} | Should -Throw + It "port variable should fall between 1024 and 65535" { + { Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential } | Should -Throw + { Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential } | Should -Throw + { Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential } | Should -Throw + { Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential } | Should -Throw } - it "has a mandatory PSCredential parameter for the credential vairable" { - Get-Command $file.BaseName | Should -HaveParameter credential -Mandatory -Type PSCredential + It "has a mandatory PSCredential parameter for the credential vairable" { + Get-Command $script:function | Should -HaveParameter credential -Mandatory -Type PSCredential } - it "should require a PSCredentialObject for the credentials" { - {Connect-ZertoServer -zertoServer -credential "MyUsername"} | Should -Throw - {Connect-ZertoServer -zertoServer -credential 1234} | Should -Throw - {Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString'})} | Should -Throw + It "should require a PSCredentialObject for the credentials" { + { Connect-ZertoServer -zertoServer -credential "MyUsername" } | Should -Throw + { Connect-ZertoServer -zertoServer -credential 1234 } | Should -Throw + { Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString' }) } | Should -Throw } } - InModuleScope ZertoApiWrapper { - Context "$($file.BaseName)::InModuleScope 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 + # and does not index the same way when imported from a JSON file. Need addtional investigation. + $xZertoSession = @("e34da0b0-4bc2-4cda-b316-0384e35bdca5") + $Headers = @{'x-zerto-session' = $xZertoSession } + $results = @{'Headers' = $Headers } + return $results + } - $server = '192.168.1.100' - $userName = "zerto\build" - $password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force - $credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) + Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite { + return (Get-Content -Path "$global:here\Mocks\LocalSiteInfo.json" -Raw | ConvertFrom-Json) + } + Context "$($script:function)::InModuleScope Function Unit Tests" { - Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { - $xZertoSession = @("7ecf544d-e7ed-4108-86f3-fb355c51cdfa") - $Headers = @{'x-zerto-session' = $xZertoSession} - $results = @{'Headers' = $Headers} - return $results + BeforeAll { + $server = '192.168.1.100' + $password = ConvertTo-SecureString -String "NotARealPassword" -AsPlainText -Force + $credential = New-Object pscredential('NotARealUser', $password) + $now = $(Get-Date).ticks + Connect-ZertoServer -zertoServer $server -credential $credential } - Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite { - $results = @{ - BandwidthThrottlingInMBs = -1 - ContactEmail = "vSphere-Site01@zerto.com" - ContactName = "vSphere-Site01@zerto.com" - ContactPhone = "066-6666666" - IpAddress = "192.168.200.1" - IsReplicationToSelfEnabled = $True - Link = @{ - href = "https://192.168.24.1:7669/v1/localsite" - identifier = "928a122b-1763-4664-ad37-cc00bb883f2f" - rel = $null - type = "LocalSiteApi" - } - Location = "vSphere-Site01" - SiteName = "vSphere-Site01 at Zerto" - SiteType = "VCenter" - UtcOffsetInMinutes = -240 - Version = "7.0.0" - SiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f" - } - return $results - } - - $now = $(Get-Date).ticks - Connect-ZertoServer -zertoServer $server -credential $credential - - it "Module Scope zvmServer variable tests" { + It "Module Scope zvmServer variable tests" { $script:zvmServer | Should -Not -BeNullOrEmpty $script:zvmServer | Should -Be $server } - it "Module Scope zvmPort variable tests" { + It "Module Scope zvmPort variable tests" { $script:zvmPort | Should -Not -BeNullOrEmpty $script:zvmPort | Should -Be '9669' } - it "Module Scope zvmLastAction variable tests" { + It "Module Scope zvmLastAction variable tests" { $script:zvmLastAction | Should -Not -BeNullOrEmpty $script:zvmLastAction | Should -BeGreaterOrEqual $now } - it "Module Scope zvmHeaders variable tests" { + It "Module Scope zvmHeaders variable tests" { $script:zvmHeaders | Should -Not -BeNullOrEmpty - $script:zvmHeaders | Should -BeOfType Hashtable + $script:zvmHeaders | Should -BeOfType PSCustomObject $script:zvmHeaders.keys.count | Should -BeExactly 2 $script:zvmHeaders.ContainsKey('x-zerto-session') | Should -BeTrue $script:zvmHeaders.ContainsKey('Accept') | Should -BeTrue @@ -130,74 +96,45 @@ Describe $file.BaseName -Tag Unit { $script:zvmHeaders['Accept'] | Should -BeOfType String } - it "Module Scope zvmLocalInfo variable tests" { + It "Module Scope zvmLocalInfo variable tests" { $script:zvmLocalInfo | Should -Not -BeNullOrEmpty - $script:zvmLocalInfo | Should -BeOfType Hashtable - $script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String - $script:zvmLocalInfo.ContainsKey('SiteIdentifier') | Should -BeTrue - $script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String + $script:zvmLocalInfo | Should -BeOfType PSCustomObject + $script:zvmLocalInfo.SiteIdentifier | Should -BeOfType String } $headers = Connect-ZertoServer -zertoServer $Server -credential $credential -returnHeaders - it "returns a Hashtable with 2 keys" { + It "returns a Hashtable with 2 keys" { $headers | Should -BeOfType Hashtable - $headers.keys.count | should be 2 + $headers.keys.count | Should be 2 } - it "return value has a key called 'x-zerto-session'" { - $headers.ContainsKey('x-zerto-session') | should be $true + It "return value has a key called 'x-zerto-session'" { + $headers.ContainsKey('x-zerto-session') | Should be $true } - it "return key 'x-zerto-session' value should be a string" { - $headers['x-zerto-session'] | should -BeOfType "String" - $headers['x-zerto-session'] | Should -BeExactly "7ecf544d-e7ed-4108-86f3-fb355c51cdfa" + It "return key 'x-zerto-session' value should be a string" { + $headers['x-zerto-session'] | Should -BeOfType "String" + $headers['x-zerto-session'] | Should -BeExactly "e34da0b0-4bc2-4cda-b316-0384e35bdca5" } - it "return value has a key called 'accept'" { - $headers.ContainsKey('accept') | should be $true + It "return value has a key called 'accept'" { + $headers.ContainsKey('accept') | Should be $true } - it "return key 'accept' value should be 'application/json'" { - $headers['accept'] | should be 'application/json' + It "return key 'accept' value should be 'application/json'" { + $headers['accept'] | Should be 'application/json' } - it "should not require a port to be specified" { + It "should not require a port to be specified" { Connect-ZertoServer -zertoServer $Server -credential $credential } - it "returns null when -ReturnHeaders is not used" { + It "returns null when -ReturnHeaders is not used" { Connect-ZertoServer -zertoServer $Server -credential $credential | Should -BeNullOrEmpty } - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 4 + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite -Exactly 4 } } } -<# -Describe "Connect-ZertoServer" -Tag Integration { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "has a function called Connect-ZertoServer" { - get-command Connect-ZertoServer | should be $true - } - $headers = Connect-ZertoServer -zertoServer $Server -zertoPort $zertoPort -credential $credential -returnHeaders - it "returns a Hashtable with 2 keys" { - $headers.keys.count | should be 2 - } - it "return value has a key called 'x-zerto-session'" { - $headers.ContainsKey('x-zerto-session') | should be $true - } - it "return key 'x-zerto-session' value should be a string" { - $headers['x-zerto-session'].gettype().name | should be "String" - } - it "return value has a key called 'accept'" { - $headers.ContainsKey('accept') | should be $true - } - it "return key 'accept' value should be 'application/json'" { - $headers['accept'] | should be 'application/json' - } - Disconnect-ZertoServer -} - #> diff --git a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 index 5be178d..9b0c57b 100644 --- a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 @@ -1,37 +1,40 @@ #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' { - Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { - $null - } - Mock -ModuleName ZertoApiWrapper -CommandName Remove-Variable { +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] +Describe $script:function -Tag 'Unit', 'Source', 'Built' { + BeforeAll { + $script:ScriptBlock = (Get-Command $script:function).ScriptBlock } - 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 - } - - Context "$($file.BaseName)::Parameter Unit Tests" { + Context "$($script:function)::Parameter Unit Tests" { it "Does not take any parameters" { (get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11 } } - Context "$($file.BaseName)::Function Unit Tests" { - it "Does not return anything" { - Disconnect-ZertoServer | Should -BeNullOrEmpty + Context "$($script: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 + # and does not index the same way when imported from a JSON file. Need addtional investigation. + $xZertoSession = @("e34da0b0-4bc2-4cda-b316-0384e35bdca5") + $Headers = @{'x-zerto-session' = $xZertoSession } + $results = @{'Headers' = $Headers } + return $results + } + + Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite { + return (Get-Content -Path "$global:here\Mocks\LocalSiteInfo.json" -Raw | ConvertFrom-Json) + } + + BeforeAll { + Connect-ZertoServer + } + + It "Does not return anything" { + Disconnect-ZertoServer | Should -BeNullOrEmpty + } } } } From f1afbe6748d133d6f6f5b2b103575d07bf70a4b1 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 14 Jul 2019 20:34:26 -0400 Subject: [PATCH 06/89] Create private helper function New-Map --- Tests/Private/New-Map.Tests.ps1 | 70 +++++++++++++++++++++++++++++ ZertoApiWrapper/Private/New-Map.ps1 | 21 +++++++++ 2 files changed, 91 insertions(+) create mode 100644 Tests/Private/New-Map.Tests.ps1 create mode 100644 ZertoApiWrapper/Private/New-Map.ps1 diff --git a/Tests/Private/New-Map.Tests.ps1 b/Tests/Private/New-Map.Tests.ps1 new file mode 100644 index 0000000..6134a02 --- /dev/null +++ b/Tests/Private/New-Map.Tests.ps1 @@ -0,0 +1,70 @@ +#Requires -Modules Pester +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] + +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + InModuleScope -ModuleName ZertoApiWrapper { + Context "$global:function::Parameter Unit Tests" { + it "have a mandatory parameter for the Input Object" { + Get-Command $global:function | Should -HaveParameter InputObject -Mandatory -Type PSCustomObject + } + + it "Input Object should not accecpt a Null or Empty value" { + $myObj = [PSCustomObject]@{ } + { New-Map -InputObject $myObj -Key "Key" -Value "Value" } | Should Throw + { New-Map -InputObject $null -Key "Key" -Value "Value" } | Should Throw + { New-Map -InputObject "" -Key "Key" -Value "Value" } | Should Throw + } + + it "have a mandatory string parameter for the Map Key" { + Get-Command $global:function | Should -HaveParameter Key -Mandatory -Type String + } + + it "The Map variable should not accecpt a Null or Empty value" { + $myObj = [PSCustomObject]@{one = 1; two = 2 } + { New-Map -InputObject $myObj -Key "" -Value "Value" } | Should Throw + { New-Map -InputObject $null -Key $null -Value "Value" } | Should Throw + { New-Map -InputObject $myObj -Key 1 -Value "Value" } | Should Throw + } + + it "The Value variable should not accecpt a Null or Empty value" { + $myObj = [PSCustomObject]@{one = 1; two = 2 } + { New-Map -InputObject $myObj -Key "Key" -Value "" } | Should Throw + { New-Map -InputObject $myObj -Key "Key" -Value $null } | Should Throw + { New-Map -InputObject $myObj -Key "Key" -Value 1 } | Should Throw + } + + it "have a mandatory string parameter for the Map Value" { + Get-Command $global:function | Should -HaveParameter Value -Mandatory -Type String + } + + it "should have an Output type of Hashtable" { + (Get-Command $global:function).OutputType.Name | Should -Match "Hashtable" + } + } + + Context "$global:function::Function Tests" { + $myObj = Get-Content "$global:here/Mocks/ProtectedVMs.json" | ConvertFrom-Json + BeforeEach { + $MyMap = New-Map -InputObject $MyObj -Key "vmIdentifier" -Value "vmName" + } + it "Returned object should be a hashtable" { + $myMap | Should -BeOfType Hashtable + } + + it "should return a hashtable with 3 entries" { + $myMap.count | should -Be 3 + } + + it "should be properly mapped" { + $myMap["vmid.12"] | Should -Be "ExchangeMailbox" + $myMap["vmid.13"] | Should -Be "ExchangeApplication" + $myMap["vmid.14"] | Should -Be "ExchangeWeb" + } + } + } +} + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global diff --git a/ZertoApiWrapper/Private/New-Map.ps1 b/ZertoApiWrapper/Private/New-Map.ps1 new file mode 100644 index 0000000..085078d --- /dev/null +++ b/ZertoApiWrapper/Private/New-Map.ps1 @@ -0,0 +1,21 @@ +function New-Map { + [CmdletBinding()] + [OutputType([Hashtable])] + param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + $inputObject, + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$key, + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$value + ) + + $returnMap = @{ } + foreach ($item in $inputObject) { + $returnMap[$item.$key] = $item.$value + } + $returnMap +} From 4fee466cc8a2d4407bc0a952734e0b5ad7e8071d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 14 Jul 2019 20:34:53 -0400 Subject: [PATCH 07/89] Add Mocks for New-Map --- Tests/Private/Mocks/ProtectedVMs.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Tests/Private/Mocks/ProtectedVMs.json diff --git a/Tests/Private/Mocks/ProtectedVMs.json b/Tests/Private/Mocks/ProtectedVMs.json new file mode 100644 index 0000000..cf4924b --- /dev/null +++ b/Tests/Private/Mocks/ProtectedVMs.json @@ -0,0 +1,15 @@ +[ + { + "VMname": "ExchangeMailbox", + "VMIdentifier": "vmid.12" + }, + { + "VMName": "ExchangeApplication", + "VmIdentifier": "vmid.13" + }, + { + "VMName": "ExchangeWeb", + "VmIdentifier": "vmid.14" + } +] + From dd144d3c477dc038d61be9ead38fe670ac1b9565 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 14 Jul 2019 20:35:47 -0400 Subject: [PATCH 08/89] Update to use New-Map helper function --- ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 | 10 ++-------- ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 index 6846145..6de8852 100644 --- a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 @@ -38,18 +38,12 @@ function Export-ZertoVmNicSetting { } $nicSettings = foreach ($group in $vpgs) { $protectedVms = Get-ZertoProtectedVm -vpgName ($group.vpgname) - $vmMap = @{ } - foreach ($vm in $protectedVms) { - $vmMap["$($vm.vmIdentifier)"] = $vm.vmName - } + $vmMap = New-Map -InputObject $protectedVms -key "vmIdentifier" -value "vmName" $settingsId = New-ZertoVpgSettingsIdentifier -vpgIdentifier $group.vpgIdentifier $vmSettings = Get-ZertoVpgSetting -vpgSettingsIdentifier $settingsId -vms $networks = Get-ZertoVirtualizationSite -siteIdentifier $group.RecoverySite.identifier -networks $null = Remove-ZertoVpgSettingsIdentifier -vpgSettingsIdentifier $settingsId - $networkMap = @{ } - foreach ($network in $networks) { - $networkMap[$network.NetworkIdentifier] = $network.VirtualizationNetworkName - } + $networkMap = New-Map -InputObject $networks -key "NetworkIdentifier" -value "VirtualizationNetworkName" foreach ($vm in $vmSettings) { $nicInfo = [PSCustomObject]@{ VPGName = $group.VPGName diff --git a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 index 8a24dec..3cdf766 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 @@ -31,15 +31,9 @@ function Import-ZertoVmNicSetting { $VpgInfo = Get-ZertoVpg -vpgName $Vpg $VpgIdentifier = $VpgInfo.VpgIdentifier $RecoveryNetworks = Get-ZertoVirtualizationSite -siteIdentifier $VpgInfo.RecoverySite.Identifier -networks - $NetworkMap = @{ } - foreach ($Network in $RecoveryNetworks) { - $NetworkMap[$Network.VirtualizationNetworkName] = $Network.NetworkIdentifier - } + $NetworkMap = New-Map -InputObject $RecoveryNetworks -key "VirtualizationNetworkName" -value "NetworkIdentifier" $VpgVms = Get-ZertoProtectedVm -vpgName $Vpg - $VmMap = @{ } - foreach ($Vm in $VpgVms) { - $VmMap[$Vm.vmName] = $Vm.vmIdentifier - } + $VmMap = New-Map -InputObject $VpgVms -key "vmName" -value "vmIdentifier" $VpgSettingsId = New-ZertoVpgSettingsIdentifier -vpgIdentifier $VpgIdentifier $VmsToUpdate = $ImportData | Where-Object { $_.VPGName -eq $Vpg } foreach ($vm in $VmsToUpdate) { From 235434fe2042fecd7f0b5780d06e8b768d40ec98 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 14 Jul 2019 20:36:32 -0400 Subject: [PATCH 09/89] Update function to global variable --- Tests/Public/Add-ZertoPeerSite.Tests.ps1 | 17 +++++++------- Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 | 21 +++++++++-------- Tests/Public/Connect-ZertoAnalytics.Tests.ps1 | 15 +++++++----- Tests/Public/Connect-ZertoServer.Tests.ps1 | 23 +++++++++++-------- Tests/Public/Disconnect-ZertoServer.Tests.ps1 | 13 +++++++---- 5 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 index 39fd439..35927f8 100644 --- a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 @@ -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 diff --git a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 index 3cc79e4..f580a6f 100644 --- a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 @@ -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 diff --git a/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 b/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 index fcfd65a..661e985 100644 --- a/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 +++ b/Tests/Public/Connect-ZertoAnalytics.Tests.ps1 @@ -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 diff --git a/Tests/Public/Connect-ZertoServer.Tests.ps1 b/Tests/Public/Connect-ZertoServer.Tests.ps1 index de54536..1cdc5b6 100644 --- a/Tests/Public/Connect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Connect-ZertoServer.Tests.ps1 @@ -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 diff --git a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 index 9b0c57b..4fe92ac 100644 --- a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 @@ -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 From e6c5effe7cd911d2fb28abe7b01eed0214a2d89b Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 11:48:13 -0400 Subject: [PATCH 10/89] Specify InputObject Type --- ZertoApiWrapper/Private/New-Map.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Private/New-Map.ps1 b/ZertoApiWrapper/Private/New-Map.ps1 index 085078d..b84ea9d 100644 --- a/ZertoApiWrapper/Private/New-Map.ps1 +++ b/ZertoApiWrapper/Private/New-Map.ps1 @@ -4,7 +4,7 @@ function New-Map { param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] - $inputObject, + [PSCustomObject]$inputObject, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$key, From 19b645bccc1ac38d7ba7f3ad2fa511976ab5d3b9 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 11:48:47 -0400 Subject: [PATCH 11/89] Exclude Common Parameters in Filter String --- .../Private/Get-ZertoApiFilter.ps1 | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 index a6400ca..c4253ca 100644 --- a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 +++ b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 @@ -1,22 +1,41 @@ function Get-ZertoApiFilter { [cmdletbinding()] + [Outputtype([String])] param( [Parameter( Mandatory = $true, HelpMessage = "Hashtable that contains filter keys and values" )] + [ValidateNotNullOrEmpty()] [hashtable]$filterTable ) # Define the start of the return string [string]$returnString = "?" - + $commonParameters = @( + "Debug" + "ErrorAction" + "ErrorVariable" + "InformationAction" + "InformationVariable" + "OutVariable" + "OutBuffer" + "PipelineVariable" + "Verbose" + "WarningAction" + "WarningVariable" + "WhatIf" + "Confirm" + ) #Foreach item in the table, process each item foreach ( $key in $filterTable.Keys ) { - #If this is not the first item added to the string, add the ampersand and filter - if ($returnString.Length -gt 1) { - $returnString = "{0}&{1}={2}" -f $returnString, $key, $filterTable[$key] - } else { - #If it is the first item, just add the first item - $returnString = "{0}{1}={2}" -f $returnString, $key, $filterTable[$key] + # If the key is not a common parameter, process it. + if ($key -notin $commonParameters) { + #If this is not the first item added to the string, add the ampersand and filter + if ($returnString.Length -gt 1) { + $returnString = "{0}&{1}={2}" -f $returnString, $key, $filterTable[$key] + } else { + #If it is the first item, just add the first item + $returnString = "{0}{1}={2}" -f $returnString, $key, $filterTable[$key] + } } } # Return the built query String From d7ee3eab122d4a07e3c032c0acba54fbabb50a65 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 15:30:54 -0400 Subject: [PATCH 12/89] Updating Formatting --- ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 index c4253ca..25b52e9 100644 --- a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 +++ b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 @@ -2,7 +2,8 @@ function Get-ZertoApiFilter { [cmdletbinding()] [Outputtype([String])] param( - [Parameter( Mandatory = $true, + [Parameter( + Mandatory = $true, HelpMessage = "Hashtable that contains filter keys and values" )] [ValidateNotNullOrEmpty()] From 562d1210e6665a539c0f4d641875f688d4dcf1b4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 15:31:44 -0400 Subject: [PATCH 13/89] Update Tests for Mutlirun --- Tests/Private/Get-ZertoApiFilter.Tests.ps1 | 89 ++++++++++++++++------ 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 index 92af238..8217b49 100644 --- a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 +++ b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 @@ -1,30 +1,71 @@ -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$file = Get-ChildItem "$filePath\$fileName" +#Requires -Modules Pester +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -. $file.FullName -$singleBoolItemTest = @{"BoolItem" = $True} -$oneItemTest = @{"OneItem" = "Test"} -$twoItemTest = @{"OneItem" = "Test"; "SecondItem" = "Yours"} -$boolItemTest = @{"OneItem" = "Test"; "BoolItem" = $true} +Describe $global:function -Tag 'Unit', 'Source', 'Built' { -Describe $file.BaseName -Tag Unit { - it "file should exist" { - $file.Fullname | should exist - } + InModuleScope -ModuleName ZertoApiWrapper { + Context "$global:function::Parameter Unit Tests" { + It "has a mandatory hashtable parameter for the filterTable" { + Get-Command $global:function | Should -HaveParameter filterTable -Mandatory -Type Hashtable + } - It "is valid Powershell (Has no script errors)" { - $contents = Get-Content -Path $file.Fullname -ErrorAction Stop - $errors = $null - $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) - $errors | Should -HaveCount 0 - } + It "FilterTable should not accecpt a Null or Empty parameter" { + { Get-ZertoApiFilter -filtertable (@{ }) } | Should Throw + { Get-ZertoApiFilter -filtertable "" } | Should Throw + { Get-ZertoApiFilter -filtertable $null } | Should Throw + } - it "converts bool to text" { - Get-ZertoApiFilter -filtertable $singleBoolItemTest | should -Be "?BoolItem=True" + it "should have an Output type of String" { + (Get-Command $global:function).OutputType.Name | Should -Match "String" + } + } + + Context "$global:function::Function Unit Tests" { + BeforeAll { + $singleBoolItemTest = @{"BoolItem" = $True } + $oneItemTest = @{ OneItem = "Test" } + $twoItemTest = @{ + OneItem = "Test" + SecondItem = "Yours" + } + $commonParamTest = @{ + Debug = $True + ErrorAction = "Stop" + ErrorVariable = "ErrVar" + InformationAction = "Continue" + InformationVariable = "InfoVar" + OutVariable = "OutVar" + OutBuffer = "OutBuff" + PipelineVariable = "PipeVar" + Verbose = $false + WarningAction = "SilentlyContinue" + WarningVariable = "WarnVar" + WhatIf = $True + Confirm = $false + OneItem = "Test" + } + } + + it "converts bool to text" { + Get-ZertoApiFilter -filtertable $singleBoolItemTest | should -Be "?BoolItem=True" + } + + it "one item test" { + Get-ZertoApiFilter -filtertable $oneItemTest | should be "?OneItem=Test" + } + + it "should ignore CommonParameters" { + Get-ZertoApiFilter -filtertable $commonParamTest | should be "?OneItem=Test" + } + + it "should process a filter table with more than one item" { + $returnString = Get-ZertoApiFilter -filtertable $twoItemTest + $returnString | Should -match "^\?" + $returnString | Should -match "&" + $returnString | Should -match "OneItem=Test" + $returnString | Should -match "SecondItem=Yours" + } + } } - it "one item test" { - Get-ZertoApiFilter -filtertable $oneItemTest | should be "?OneItem=Test" - } - #TODO:: Figure out multi-item tests } From db91acb7702e0f0cd3ace6c8a582f565086261d3 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 16 Jul 2019 14:11:01 -0400 Subject: [PATCH 14/89] remove global variables when complete --- Tests/Private/Get-ZertoApiFilter.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 index 8217b49..a4b5978 100644 --- a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 +++ b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 @@ -69,3 +69,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { } } } + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 40326da05fd676f0f62ed53cdb02a45649e9a63e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 16 Jul 2019 14:16:06 -0400 Subject: [PATCH 15/89] Update to ThrowErrors when required vars missing --- ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 b/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 index 1e35829..de6869b 100644 --- a/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 +++ b/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 @@ -1,19 +1,23 @@ function Invoke-ZARestRequest { [cmdletbinding()] param( + # Parameter help description + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] [string]$uri, + [ValidateSet("GET", "PUT", "POST", "DELETE")] [string]$method = "GET", + [ValidateNotNullOrEmpty()] [string]$body, + [ValidateNotNullOrEmpty()] [string]$contentType = "application/json" ) # Check to see if the required variables are present and currently valid if ( -not ((Test-Path variable:script:zaLastActionTime) -and (Test-Path variable:script:zaHeaders)) ) { - Write-Error -Message "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection" - break + ThrowError -ExceptionName "NoAuth" -ExceptionMessage "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection" -errorId "Auth02" -errorCategory "ZertoAuth" -ErrorAction Stop } elseif ( (Test-Path variable:script:zaHeaders) -and $([datetime]$script:zaLastActionTime).addMinutes(60) -lt $(get-date) ) { - Write-Error -Message "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal" - break + ThrowError -ExceptionName "ExpiredToken" -ExceptionMessage "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal" -errorId "Auth01" -errorCategory "ZertoAuth" -ErrorAction Stop } else { # Update the last action time and submit the request based on PS Version. Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks From 6b05af2db427d464cc56fc4944d658230bec4a52 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 16 Jul 2019 14:52:22 -0400 Subject: [PATCH 16/89] Update Invoke-ZARestRequest.Tests.ps1 --- Tests/Private/Invoke-ZARestRequest.Tests.ps1 | 106 ++++++++++++++++--- 1 file changed, 92 insertions(+), 14 deletions(-) diff --git a/Tests/Private/Invoke-ZARestRequest.Tests.ps1 b/Tests/Private/Invoke-ZARestRequest.Tests.ps1 index 984d682..b76f320 100644 --- a/Tests/Private/Invoke-ZARestRequest.Tests.ps1 +++ b/Tests/Private/Invoke-ZARestRequest.Tests.ps1 @@ -1,17 +1,95 @@ -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$file = Get-ChildItem "$filePath\$fileName" -. $file.FullName +#Requires -Modules Pester +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag Unit { - it "file should exist" { - $file.FullName | should exist - } +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - It "is valid Powershell (Has no script errors)" { - $contents = Get-Content -Path $file.FullName -ErrorAction Stop - $errors = $null - $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) - $errors | Should -HaveCount 0 + InModuleScope -ModuleName ZertoApiWrapper { + + Context "$global:function::Parameter Unit Tests" { + + it "have a mandatory string parameter for the URI Variable" { + Get-Command Invoke-ZARestRequest | Should -HaveParameter uri -Mandatory -Type String + } + + it "have a non-mandatory string parameter for the Method Variable, default to 'GET'" { + Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Type String + Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Not -Mandatory + Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -DefaultValue "GET" + } + + it "have a non-mandatory string parameter for the Body variable" { + Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Type String + Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Not -Mandatory + } + + it "have a non-mandatory string parameter for the contentType variable" { + Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Type String + Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Not -Mandatory + Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -DefaultValue "application/json" + } + + it "uri variable does not accecpt a null or empty variable" { + { Invoke-ZARestRequest -uri $null } | Should Throw + { Invoke-ZARestRequest -uri "" } | Should Throw + } + + it "method variable only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" { + $parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters['method'] + $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + $validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] } + $validateSet.ValidValues -contains 'GET' | Should -BeTrue + $validateSet.ValidValues -contains 'PUT' | Should -BeTrue + $validateSet.ValidValues -contains 'POST' | Should -BeTrue + $validateSet.ValidValues -contains 'DELETE' | Should -BeTrue + $validateSet.ValidValues.Count | Should -Be 4 + } + + it "body variable does not accecpt a null or empty variable" { + { Invoke-ZARestRequest -uri "connect" -body $null } | Should Throw + { Invoke-ZARestRequest -uri "connect" -body "" } | Should Throw + } + + it "accecpt variable does not accecpt a null or empty variable" { + { Invoke-ZARestRequest -uri "connect" -accecpt $null } | Should Throw + { Invoke-ZARestRequest -uri "connect" -accecpt "" } | Should Throw + } + } + + Context "$global:function::Function Unit Tests" { + + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-RestMethod { + "Ran Command" + } + + BeforeEach { + Set-Variable -Name zaHeaders -Scope Script -Value (@{ "Accept" = "application/json" }) + Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks + } + + it "runs when called" { + Invoke-ZARestRequest -uri "myuri" | Should Be "Ran Command" + } + + it "throws when the last action was over 60 minutes ago" { + $script:zaLastActionTime = (get-date).AddMinutes(-61).Ticks + { Invoke-ZARestRequest -uri "myuri" } | Should Throw + } + + it "throws when the zaHeaders variable does not exits" { + Remove-Variable -Name zaHeaders -Scope Script + { Invoke-ZARestRequest -uri "myuri" } | Should Throw + } + + it "throws when the zaLastActionTime variable does not exits" { + Remove-Variable -Name zaLastActionTime -Scope Script + { Invoke-ZARestRequest -uri "myuri" } | Should Throw + } + + Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1 + } } -} \ No newline at end of file +} + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 1c17ca3e96b7dc1a4567ee62deff28d120b3211c Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 18 Jul 2019 21:25:18 -0400 Subject: [PATCH 17/89] Update Invoke-ZertoRestRequest.ps1 --- .../Private/Invoke-ZertoRestRequest.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 b/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 index 342a1fd..7bc453e 100644 --- a/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 +++ b/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 @@ -1,26 +1,29 @@ function Invoke-ZertoRestRequest { [cmdletbinding()] param( + [ValidateSet("GET", "PUT", "POST", "DELETE")] [string]$method = "GET", + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] [string]$uri, + [ValidateNotNullOrEmpty()] [string]$apiVersion = "v1", + [ValidateNotNullOrEmpty()] [string]$body, + [ValidateNotNullOrEmpty()] [string]$contentType = "application/json", - [System.Management.Automation.PSCredential] - $credential, + [PSCredential]$credential, [switch]$returnHeaders ) $callerErrorActionPreference = $ErrorActionPreference # If the ZVM server and Port not defined, Stop Call if ( -not ((Test-Path variable:script:zvmServer) -and (Test-Path variable:script:zvmPort)) ) { - Write-Error -Message "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection" - break + ThrowError -ExceptionName "NoConnection" -ExceptionMessage "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection" -errorId "Connection01" -errorCategory "Connection" -ErrorAction Stop } # If the Headers exist and the Last action was more than 30 minutes ago, Session is Expired if ( (Test-Path variable:script:zvmHeaders) -and $([datetime]$script:zvmLastAction).addMinutes(30) -lt $(get-date) ) { - Write-Error -Message "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager" - break + ThrowError -ExceptionName "ExpiredToken" -ExceptionMessage "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager" -errorId "ZVMAuth01" -errorCategory "Auth" -ErrorAction Stop } else { # Build the URI to be submitted @@ -57,7 +60,7 @@ public class TrustAllCertsPolicy : ICertificatePolicy { # If we are authenticating to the ZVM, Use this block to use Invoke-WebRequest and format the Headers as expected. if ($uri -eq "session/add" -and $method -eq "POST") { $apiRequestResults = Invoke-WebRequest -Uri $submittedURI -Headers $script:zvmHeaders -Method $method -Body $body -ContentType $contentType -Credential $credential -TimeoutSec 100 - $responseHeaders = @{} + $responseHeaders = @{ } $responseHeaders['x-zerto-session'] = @($apiRequestResults.Headers['x-zerto-session']) } elseif ($method -ne "GET") { # If the Method is something other than 'GET' use this call with a body parameter From 2e6a37bd5f708641b35b3681a67447a93c7f0688 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 18 Jul 2019 21:25:20 -0400 Subject: [PATCH 18/89] Update Invoke-ZertoRestRequest.Tests.ps1 --- .../Private/Invoke-ZertoRestRequest.Tests.ps1 | 125 ++++++++++++++++-- 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 index 984d682..ffcd1dc 100644 --- a/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 +++ b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 @@ -1,17 +1,114 @@ -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$file = Get-ChildItem "$filePath\$fileName" -. $file.FullName +#Requires -Modules Pester +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag Unit { - it "file should exist" { - $file.FullName | should exist - } +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - It "is valid Powershell (Has no script errors)" { - $contents = Get-Content -Path $file.FullName -ErrorAction Stop - $errors = $null - $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) - $errors | Should -HaveCount 0 + InModuleScope -ModuleName ZertoApiWrapper { + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-RestMethod { + "Ran Command" + } + + Context "$global:function::Parameter Unit Tests" { + $thisCommand = get-command Invoke-ZertoRestRequest + it "has a mandatory string parameter for the uri" { + $thisCommand | Should -HaveParameter uri -Mandatory -Type String + } + + it "uri parameter cannot be null or empty" { + $thisParameter = $thisCommand.Parameters['uri'] + $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 + } + + it "has a non-mandatory string parameter for the method" { + $thisCommand | Should -HaveParameter method -Not -Mandatory + $thisCommand | Should -HaveParameter method -Type String + } + + it "method parameter can only be 'GET', 'POST', 'PUT', 'DELETE'" { + $thisParameter = $thisCommand.Parameters['method'] + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should Be 1 + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'GET' | Should -BeTrue + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'PUT' | Should -BeTrue + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'POST' | Should -BeTrue + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'DELETE' | Should -BeTrue + $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues.Count | Should -Be 4 + } + + it "has a non-mandatory string parameter for the apiVersion, default 'v1'" { + $thisCommand | Should -HaveParameter apiVersion -Not -Mandatory + $thisCommand | Should -HaveParameter apiVersion -Type String + $thisCommand | Should -HaveParameter apiVersion -DefaultValue "v1" + } + + it "apiVersion parameter cannot be null or empty" { + $thisParameter = $thisCommand.Parameters['apiVersion'] + $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 + } + + it "has a non-mandatory string parameter for the body" { + $thisCommand | Should -HaveParameter body -Not -Mandatory + $thisCommand | Should -HaveParameter body -Type String + } + + it "apiVersion parameter cannot be null or empty" { + $thisParameter = $thisCommand.Parameters['body'] + $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 + } + + it "has a non-mandatory string parameter for the contentType" { + $thisCommand | Should -HaveParameter contentType -Not -Mandatory + $thisCommand | Should -HaveParameter contentType -Type String + $thisCommand | Should -HaveParameter contentType -DefaultValue "application/json" + } + + it "apiVersion parameter cannot be null or empty" { + $thisParameter = $thisCommand.Parameters['contentType'] + $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 + } + + it "has a non-mandatory PSCredential parameter for the credential" { + $thisCommand | Should -HaveParameter credential -Type PSCredential + $thisCommand | Should -HaveParameter credential -not -mandatory + } + + it "has a non-mandatory switch parameter to ReturnHeaders" { + $thisCommand | Should -HaveParameter returnHeaders -Type Switch + $thisCommand | Should -HaveParameter returnHeaders -Not -Mandatory + } + + } + + Context "$global:function::Function Unit Tests" { + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-RestMethod { + "Ran Command" + } + + BeforeEach { + Set-Variable -Name zvmHeaders -Scope Script -Value (@{ "Accept" = "application/json" }) + Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-date).Ticks + Set-Variable -Name zvmServer -Scope Script -Value "192.168.1.100" + Set-Variable -Name zvmPort -Scope Script -Value 9669 + } + + it "runs when called" { + Invoke-ZertoRestRequest -uri "MyUri" | Should -Be "Ran Command" + } + + it "throws an error when zvmLastAction was more than 30 minutes ago" { + Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-date).AddMinutes(-31).Ticks + { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw + } + + it "throws an error when the zvmServer variable does not exist" { + Remove-Variable -Name zvmServer -Scope Script + { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw + } + + Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1 + } } -} \ No newline at end of file +} + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 670fbdbba8397abb08a6986ecead9fa149dae904 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 19 Jul 2019 11:54:11 -0400 Subject: [PATCH 19/89] Change ThrowError to Throw --- ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 b/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 index de6869b..0304c88 100644 --- a/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 +++ b/ZertoApiWrapper/Private/Invoke-ZARestRequest.ps1 @@ -15,9 +15,9 @@ function Invoke-ZARestRequest { # Check to see if the required variables are present and currently valid if ( -not ((Test-Path variable:script:zaLastActionTime) -and (Test-Path variable:script:zaHeaders)) ) { - ThrowError -ExceptionName "NoAuth" -ExceptionMessage "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection" -errorId "Auth02" -errorCategory "ZertoAuth" -ErrorAction Stop + Throw "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection" } elseif ( (Test-Path variable:script:zaHeaders) -and $([datetime]$script:zaLastActionTime).addMinutes(60) -lt $(get-date) ) { - ThrowError -ExceptionName "ExpiredToken" -ExceptionMessage "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal" -errorId "Auth01" -errorCategory "ZertoAuth" -ErrorAction Stop + Throw "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal" } else { # Update the last action time and submit the request based on PS Version. Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks From 82dbe7ae486acd69eb38f6cd33ead2d5a2d0ba9a Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 19 Jul 2019 13:47:53 -0400 Subject: [PATCH 20/89] Update Invoke-ZARestRequest.Tests.ps1 --- Tests/Private/Invoke-ZARestRequest.Tests.ps1 | 77 ++++++++++---------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/Tests/Private/Invoke-ZARestRequest.Tests.ps1 b/Tests/Private/Invoke-ZARestRequest.Tests.ps1 index b76f320..78bb6f3 100644 --- a/Tests/Private/Invoke-ZARestRequest.Tests.ps1 +++ b/Tests/Private/Invoke-ZARestRequest.Tests.ps1 @@ -8,33 +8,44 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "have a mandatory string parameter for the URI Variable" { - Get-Command Invoke-ZARestRequest | Should -HaveParameter uri -Mandatory -Type String + $testCases = @( + @{ParameterName = 'uri'; Type = 'String'; Mandatory = $true; TestName = 'URI' } + @{ParameterName = 'method'; Type = 'String'; Mandatory = $false; TestName = 'Method' } + @{ParameterName = 'body'; Type = 'String'; Mandatory = $false; TestName = 'Body' } + @{ParameterName = 'contentType'; Type = 'String'; Mandatory = $false; TestName = 'contentType' } + ) + + It "Parameter present and Type test for: " -TestCases $testCases { + param($parameterName, $type, $Mandatory) + Get-Command $global:function | Should -HaveParameter $parameterName -Type $type + if ($Mandatory) { + Get-Command $global:function | Should -HaveParameter $parameterName -Mandatory + } else { + Get-Command $global:function | Should -HaveParameter $parameterName -Not -Mandatory + } } - it "have a non-mandatory string parameter for the Method Variable, default to 'GET'" { - Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Type String - Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -Not -Mandatory - Get-Command Invoke-ZARestRequest | Should -HaveParameter Method -DefaultValue "GET" + It "Method parameter default is 'GET'" { + Get-Command $global:function | Should -HaveParameter Method -DefaultValue "GET" } - it "have a non-mandatory string parameter for the Body variable" { - Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Type String - Get-Command Invoke-ZARestRequest | Should -HaveParameter Body -Not -Mandatory + It "ContentType parameter default is 'application/json'" { + Get-Command $global:function | Should -HaveParameter contentType -DefaultValue "application/json" } - it "have a non-mandatory string parameter for the contentType variable" { - Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Type String - Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -Not -Mandatory - Get-Command Invoke-ZARestRequest | Should -HaveParameter contentType -DefaultValue "application/json" + $NotNullOrEmptyTests = @( + @{ParameterName = 'uri'; TestName = 'Uri' } + @{ParameterName = 'body'; TestName = 'Body' } + @{ParameterName = 'contentType'; TestName = 'ContentType' } + ) + + It " parameter does not accecpt a null or empty value" -TestCases $NotNullOrEmptyTests { + param($parameterName) + $parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters[$parameterName] + $parameterInfo.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 } - it "uri variable does not accecpt a null or empty variable" { - { Invoke-ZARestRequest -uri $null } | Should Throw - { Invoke-ZARestRequest -uri "" } | Should Throw - } - - it "method variable only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" { + It "method parametert only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" { $parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters['method'] $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 $validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] } @@ -44,16 +55,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $validateSet.ValidValues -contains 'DELETE' | Should -BeTrue $validateSet.ValidValues.Count | Should -Be 4 } - - it "body variable does not accecpt a null or empty variable" { - { Invoke-ZARestRequest -uri "connect" -body $null } | Should Throw - { Invoke-ZARestRequest -uri "connect" -body "" } | Should Throw - } - - it "accecpt variable does not accecpt a null or empty variable" { - { Invoke-ZARestRequest -uri "connect" -accecpt $null } | Should Throw - { Invoke-ZARestRequest -uri "connect" -accecpt "" } | Should Throw - } } Context "$global:function::Function Unit Tests" { @@ -64,26 +65,26 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { BeforeEach { Set-Variable -Name zaHeaders -Scope Script -Value (@{ "Accept" = "application/json" }) - Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks + Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-Date).Ticks } - it "runs when called" { + It "runs when called" { Invoke-ZARestRequest -uri "myuri" | Should Be "Ran Command" } - it "throws when the last action was over 60 minutes ago" { - $script:zaLastActionTime = (get-date).AddMinutes(-61).Ticks - { Invoke-ZARestRequest -uri "myuri" } | Should Throw + It "throws when the last action was over 60 minutes ago" { + $script:zaLastActionTime = (Get-Date).AddMinutes(-61).Ticks + { Invoke-ZARestRequest -uri "myuri" } | Should Throw "Authorization Token has Expired." } - it "throws when the zaHeaders variable does not exits" { + It "throws when the zaHeaders variable does not exits" { Remove-Variable -Name zaHeaders -Scope Script - { Invoke-ZARestRequest -uri "myuri" } | Should Throw + { Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist." } - it "throws when the zaLastActionTime variable does not exits" { + It "throws when the zaLastActionTime variable does not exist" { Remove-Variable -Name zaLastActionTime -Scope Script - { Invoke-ZARestRequest -uri "myuri" } | Should Throw + { Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist." } Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1 From 1cfc07260f35fd9ea2268b840eac67ab32289684 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 19 Jul 2019 14:22:39 -0400 Subject: [PATCH 21/89] Remove unused BeforAll Block --- Tests/Public/Disconnect-ZertoServer.Tests.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 index 4fe92ac..873fab2 100644 --- a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 @@ -3,13 +3,10 @@ $global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] Describe $global:function -Tag 'Unit', 'Source', 'Built' { - BeforeAll { - $script:ScriptBlock = (Get-Command $global:function).ScriptBlock - } Context "$($global:function)::Parameter Unit Tests" { - it "Does not take any parameters" { - (get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11 + It "Does not take any parameters" { + (Get-Command disconnect-zertoserver).parameters.count | Should -BeExactly 11 } } From 0c4643a76eb697a51822f6de895b528dde8411e4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 19 Jul 2019 14:22:56 -0400 Subject: [PATCH 22/89] Change ThrowError to Throw --- ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 b/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 index 7bc453e..4a3f642 100644 --- a/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 +++ b/ZertoApiWrapper/Private/Invoke-ZertoRestRequest.ps1 @@ -18,12 +18,12 @@ function Invoke-ZertoRestRequest { $callerErrorActionPreference = $ErrorActionPreference # If the ZVM server and Port not defined, Stop Call if ( -not ((Test-Path variable:script:zvmServer) -and (Test-Path variable:script:zvmPort)) ) { - ThrowError -ExceptionName "NoConnection" -ExceptionMessage "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection" -errorId "Connection01" -errorCategory "Connection" -ErrorAction Stop + Throw "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection" } # If the Headers exist and the Last action was more than 30 minutes ago, Session is Expired if ( (Test-Path variable:script:zvmHeaders) -and $([datetime]$script:zvmLastAction).addMinutes(30) -lt $(get-date) ) { - ThrowError -ExceptionName "ExpiredToken" -ExceptionMessage "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager" -errorId "ZVMAuth01" -errorCategory "Auth" -ErrorAction Stop + Throw "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager" } else { # Build the URI to be submitted From 86ac714c22da6a2258a4f550a1958b10e051a0d0 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 19 Jul 2019 14:23:16 -0400 Subject: [PATCH 23/89] Use TestCases --- .../Private/Invoke-ZertoRestRequest.Tests.ps1 | 101 +++++++----------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 index ffcd1dc..df40da6 100644 --- a/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 +++ b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 @@ -10,22 +10,44 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { } Context "$global:function::Parameter Unit Tests" { - $thisCommand = get-command Invoke-ZertoRestRequest - it "has a mandatory string parameter for the uri" { - $thisCommand | Should -HaveParameter uri -Mandatory -Type String + $thisCommand = Get-Command Invoke-ZertoRestRequest + $ParameterNameTestCases = @( + @{ParameterName = "uri"; Type = "String"; Mandatory = $true; DefaultValue = $null; TestName = "URI" } + @{ParameterName = "method"; Type = "String"; Mandatory = $false; DefaultValue = 'GET'; TestName = "Method" } + @{ParameterName = "apiVersion"; Type = "String"; Mandatory = $false; DefaultValue = 'v1'; TestName = "API Version" } + @{ParameterName = "body"; Type = "String"; Mandatory = $false; DefaultValue = $null; TestName = "Body" } + @{ParameterName = "contentType"; Type = "String"; Mandatory = $false; DefaultValue = 'application/json'; TestName = "Content Type" } + @{ParameterName = "credential"; Type = "PSCredential"; Mandatory = $false; DefaultValue = $null; TestName = "Credential" } + @{ParameterName = "returnHeaders"; Type = "Switch"; Mandatory = $false; DefaultValue = $null; TestName = "Return Headers" } + ) + + It " parameter has the right Type, Default Value, and Mandatory Setting" -TestCases $ParameterNameTestCases { + param($ParameterName, $Type, $DefaultValue, $Mandatory) + if ($Mandatory) { + $thisCommand | Should -HaveParameter $ParameterName -Type $Type -Mandatory + } else { + $thisCommand | Should -HaveParameter $ParameterName -Type $Type + $thisCommand | Should -HaveParameter $ParameterName -Not -Mandatory + } + if ($null -ne $DefaultValue) { + $thisCommand | Should -HaveParameter $ParameterName -DefaultValue $DefaultValue + } } - it "uri parameter cannot be null or empty" { - $thisParameter = $thisCommand.Parameters['uri'] + $ParameterValidationTestCases = @( + @{ParameterName = "URI"; TestName = "URI" } + @{ParameterName = "apiVersion"; TestName = "Api Version" } + @{ParameterName = "body"; TestName = "Body" } + @{ParameterName = "contentType"; TestName = "Content Type" } + ) + + It " parameter cannot be null or empty" -TestCases $ParameterValidationTestCases { + param($ParameterName) + $thisParameter = $thisCommand.Parameters[$ParameterName] $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 } - it "has a non-mandatory string parameter for the method" { - $thisCommand | Should -HaveParameter method -Not -Mandatory - $thisCommand | Should -HaveParameter method -Type String - } - - it "method parameter can only be 'GET', 'POST', 'PUT', 'DELETE'" { + It "Method parameter can only be 'GET', 'POST', 'PUT', 'DELETE'" { $thisParameter = $thisCommand.Parameters['method'] $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should Be 1 $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'GET' | Should -BeTrue @@ -34,49 +56,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues -contains 'DELETE' | Should -BeTrue $thisParameter.Attributes.Where{ $_ -is [ValidateSet] }.validValues.Count | Should -Be 4 } - - it "has a non-mandatory string parameter for the apiVersion, default 'v1'" { - $thisCommand | Should -HaveParameter apiVersion -Not -Mandatory - $thisCommand | Should -HaveParameter apiVersion -Type String - $thisCommand | Should -HaveParameter apiVersion -DefaultValue "v1" - } - - it "apiVersion parameter cannot be null or empty" { - $thisParameter = $thisCommand.Parameters['apiVersion'] - $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 - } - - it "has a non-mandatory string parameter for the body" { - $thisCommand | Should -HaveParameter body -Not -Mandatory - $thisCommand | Should -HaveParameter body -Type String - } - - it "apiVersion parameter cannot be null or empty" { - $thisParameter = $thisCommand.Parameters['body'] - $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 - } - - it "has a non-mandatory string parameter for the contentType" { - $thisCommand | Should -HaveParameter contentType -Not -Mandatory - $thisCommand | Should -HaveParameter contentType -Type String - $thisCommand | Should -HaveParameter contentType -DefaultValue "application/json" - } - - it "apiVersion parameter cannot be null or empty" { - $thisParameter = $thisCommand.Parameters['contentType'] - $thisParameter.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 - } - - it "has a non-mandatory PSCredential parameter for the credential" { - $thisCommand | Should -HaveParameter credential -Type PSCredential - $thisCommand | Should -HaveParameter credential -not -mandatory - } - - it "has a non-mandatory switch parameter to ReturnHeaders" { - $thisCommand | Should -HaveParameter returnHeaders -Type Switch - $thisCommand | Should -HaveParameter returnHeaders -Not -Mandatory - } - } Context "$global:function::Function Unit Tests" { @@ -86,23 +65,23 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { BeforeEach { Set-Variable -Name zvmHeaders -Scope Script -Value (@{ "Accept" = "application/json" }) - Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-date).Ticks + Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-Date).Ticks Set-Variable -Name zvmServer -Scope Script -Value "192.168.1.100" Set-Variable -Name zvmPort -Scope Script -Value 9669 } - it "runs when called" { + It "runs when called" { Invoke-ZertoRestRequest -uri "MyUri" | Should -Be "Ran Command" } - it "throws an error when zvmLastAction was more than 30 minutes ago" { - Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-date).AddMinutes(-31).Ticks - { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw + It "throws an error when zvmLastAction was more than 30 minutes ago" { + Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-Date).AddMinutes(-31).Ticks + { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw "Authorization Token has Expired" } - it "throws an error when the zvmServer variable does not exist" { + It "throws an error when the zvmServer variable does not exist" { Remove-Variable -Name zvmServer -Scope Script - { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw + { Invoke-ZertoRestRequest -uri "MyUri" } | Should Throw "Zerto Connection does not Exist." } Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1 From 997ab900350b8e51d5a85fab0d1984eb1edf04ef Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 11:37:22 -0400 Subject: [PATCH 24/89] Add Mock File for Single VRA Information --- Tests/Public/Mocks/GetSingleVra.json | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Tests/Public/Mocks/GetSingleVra.json diff --git a/Tests/Public/Mocks/GetSingleVra.json b/Tests/Public/Mocks/GetSingleVra.json new file mode 100644 index 0000000..df9776c --- /dev/null +++ b/Tests/Public/Mocks/GetSingleVra.json @@ -0,0 +1,50 @@ +{ + "DatastoreClusterIdentifier": null, + "DatastoreClusterName": null, + "DatastoreIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.datastore-19", + "DatastoreName": "datastore1", + "HostIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.host-15", + "HostVersion": "6.7", + "IpAddress": "192.168.10.15", + "Link": { + "href": "https://192.168.10.20:9669/v1/vras/5377857665828093654", + "identifier": "5377857665828093654", + "rel": null, + "type": "VraApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vras/5377857665828093654", + "rel": "self", + "type": "VraApi" + }, + "MemoryInGB": 1, + "NetworkIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.network-22", + "NetworkName": "VM Network", + "Progress": 0, + "ProtectedCounters": { + "Vms": 0, + "Volumes": 0, + "Vpgs": 0 + }, + "RecoveryCounters": { + "Vms": 0, + "Volumes": 0, + "Vpgs": 0 + }, + "SelfProtectedVpgs": 0, + "Status": 0, + "VraAlerts": { + "VraAlertsStatus": 0 + }, + "VraGroup": "default_group", + "VraIdentifier": 5377857665828093654, + "VraIdentifierStr": "5377857665828093654", + "VraName": "Z-VRA-ncesx2.nc.lab", + "VraNetworkDataApi": { + "DefaultGateway": "192.168.10.254", + "SubnetMask": "255.255.255.0", + "VraIPAddress": "192.168.10.15", + "VraIPConfigurationTypeApi": "Static" + }, + "VraVersion": "7.0" +} From 9ab97f27862f60fa3ed3d98505d94267fcfb4f70 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 11:39:05 -0400 Subject: [PATCH 25/89] Update Test Template for both source and built tests --- Tests/Public/Get-ZAAlert.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZADatastore.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAEvent.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalAverageHistory.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZAJournalAverageSize.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAJournalBreach.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZAJournalHistoryStat.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalSiteAverageHistory.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalSiteAverageSize.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalSiteHistoryStat.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalSiteHistorySummary.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalSiteSizeStat.Tests.ps1 | 26 ++++++++--------- .../Get-ZAJournalStatusProportion.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZAJournalStorageStat.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAJournalSummary.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZALicense.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZAMonitoring.Tests.ps1 | 28 +++++++++--------- .../Get-ZANetworkSiteAverageIOPS.Tests.ps1 | 26 ++++++++--------- ...-ZANetworkSiteAveragePerformance.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZANetworkSiteSummary.Tests.ps1 | 26 ++++++++--------- .../Get-ZANetworkVpgAverageIOPS.Tests.ps1 | 26 ++++++++--------- ...t-ZANetworkVpgAveragePerformance.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZANetworkVpgSummary.Tests.ps1 | 26 ++++++++--------- .../Public/Get-ZARPOAccountAverage.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZARPOAverage.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZARPOBreach.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZARPOStat.Tests.ps1 | 26 ++++++++--------- .../Get-ZARPOStatusProportion.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZARPOSummary.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZASite.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZASitePair.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZASiteTopology.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZATask.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAVolume.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAVpg.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZAzOrg.Tests.ps1 | 26 ++++++++--------- Tests/Public/Get-ZertoEvent.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoLicense.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoPeerSite.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoProtectedVm.Tests.ps1 | 28 +++++++++--------- .../Public/Get-ZertoRecoveryReport.Tests.ps1 | 28 +++++++++--------- .../Public/Get-ZertoResourcesReport.Tests.ps1 | 28 +++++++++--------- .../Public/Get-ZertoServiceProfile.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoTask.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 | 28 +++++++++--------- .../Get-ZertoVirtualizationSite.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoVolume.Tests.ps1 | 29 +++++++++---------- Tests/Public/Get-ZertoVpg.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoVpgSetting.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoVra.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoZorg.Tests.ps1 | 28 +++++++++--------- Tests/Public/Get-ZertoZsspSession.Tests.ps1 | 28 +++++++++--------- Tests/Public/New-ZertoVpg.Tests.ps1 | 28 +++++++++--------- .../New-ZertoVpgSettingsIdentifier.Tests.ps1 | 28 +++++++++--------- Tests/Public/Remove-ZertoPeerSite.Tests.ps1 | 28 +++++++++--------- Tests/Public/Remove-ZertoVpg.Tests.ps1 | 28 +++++++++--------- ...emove-ZertoVpgSettingsIdentifier.Tests.ps1 | 26 ++++++++--------- Tests/Public/Resume-ZertoVpg.Tests.ps1 | 28 +++++++++--------- Tests/Public/Save-ZertoVpgSetting.Tests.ps1 | 28 +++++++++--------- Tests/Public/Set-ZertoAlert.Tests.ps1 | 28 +++++++++--------- Tests/Public/Set-ZertoLicense.Tests.ps1 | 28 +++++++++--------- Tests/Public/Start-ZertoCloneVpg.Tests.ps1 | 28 +++++++++--------- .../Public/Start-ZertoFailoverTest.Tests.ps1 | 28 +++++++++--------- Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 | 28 +++++++++--------- Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 | 28 +++++++++--------- Tests/Public/Suspend-ZertoVpg.Tests.ps1 | 28 +++++++++--------- Tests/Public/Uninstall-ZertoVra.Tests.ps1 | 28 +++++++++--------- 69 files changed, 861 insertions(+), 998 deletions(-) diff --git a/Tests/Public/Get-ZAAlert.Tests.ps1 b/Tests/Public/Get-ZAAlert.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAAlert.Tests.ps1 +++ b/Tests/Public/Get-ZAAlert.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZADatastore.Tests.ps1 b/Tests/Public/Get-ZADatastore.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZADatastore.Tests.ps1 +++ b/Tests/Public/Get-ZADatastore.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAEvent.Tests.ps1 b/Tests/Public/Get-ZAEvent.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAEvent.Tests.ps1 +++ b/Tests/Public/Get-ZAEvent.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 b/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 b/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalBreach.Tests.ps1 b/Tests/Public/Get-ZAJournalBreach.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalBreach.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalBreach.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 b/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 b/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 b/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAJournalSummary.Tests.ps1 b/Tests/Public/Get-ZAJournalSummary.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAJournalSummary.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSummary.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZALicense.Tests.ps1 b/Tests/Public/Get-ZALicense.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZALicense.Tests.ps1 +++ b/Tests/Public/Get-ZALicense.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAMonitoring.Tests.ps1 b/Tests/Public/Get-ZAMonitoring.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZAMonitoring.Tests.ps1 +++ b/Tests/Public/Get-ZAMonitoring.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 b/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 +++ b/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOAverage.Tests.ps1 b/Tests/Public/Get-ZARPOAverage.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOAverage.Tests.ps1 +++ b/Tests/Public/Get-ZARPOAverage.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOBreach.Tests.ps1 b/Tests/Public/Get-ZARPOBreach.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOBreach.Tests.ps1 +++ b/Tests/Public/Get-ZARPOBreach.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOStat.Tests.ps1 b/Tests/Public/Get-ZARPOStat.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOStat.Tests.ps1 +++ b/Tests/Public/Get-ZARPOStat.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 b/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 +++ b/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZARPOSummary.Tests.ps1 b/Tests/Public/Get-ZARPOSummary.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZARPOSummary.Tests.ps1 +++ b/Tests/Public/Get-ZARPOSummary.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZASite.Tests.ps1 b/Tests/Public/Get-ZASite.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZASite.Tests.ps1 +++ b/Tests/Public/Get-ZASite.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZASitePair.Tests.ps1 b/Tests/Public/Get-ZASitePair.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZASitePair.Tests.ps1 +++ b/Tests/Public/Get-ZASitePair.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZASiteTopology.Tests.ps1 b/Tests/Public/Get-ZASiteTopology.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZASiteTopology.Tests.ps1 +++ b/Tests/Public/Get-ZASiteTopology.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZATask.Tests.ps1 b/Tests/Public/Get-ZATask.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZATask.Tests.ps1 +++ b/Tests/Public/Get-ZATask.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAVolume.Tests.ps1 b/Tests/Public/Get-ZAVolume.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAVolume.Tests.ps1 +++ b/Tests/Public/Get-ZAVolume.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAVpg.Tests.ps1 b/Tests/Public/Get-ZAVpg.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAVpg.Tests.ps1 +++ b/Tests/Public/Get-ZAVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZAzOrg.Tests.ps1 b/Tests/Public/Get-ZAzOrg.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Get-ZAzOrg.Tests.ps1 +++ b/Tests/Public/Get-ZAzOrg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoEvent.Tests.ps1 b/Tests/Public/Get-ZertoEvent.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoEvent.Tests.ps1 +++ b/Tests/Public/Get-ZertoEvent.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoLicense.Tests.ps1 b/Tests/Public/Get-ZertoLicense.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoLicense.Tests.ps1 +++ b/Tests/Public/Get-ZertoLicense.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 b/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 +++ b/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 b/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 +++ b/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 b/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 +++ b/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 b/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 +++ b/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoTask.Tests.ps1 b/Tests/Public/Get-ZertoTask.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoTask.Tests.ps1 +++ b/Tests/Public/Get-ZertoTask.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 b/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 +++ b/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 b/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoVolume.Tests.ps1 b/Tests/Public/Get-ZertoVolume.Tests.ps1 index 50d2f9d..4b86f54 100644 --- a/Tests/Public/Get-ZertoVolume.Tests.ps1 +++ b/Tests/Public/Get-ZertoVolume.Tests.ps1 @@ -1,19 +1,18 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global + diff --git a/Tests/Public/Get-ZertoVpg.Tests.ps1 b/Tests/Public/Get-ZertoVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Get-ZertoVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 b/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 +++ b/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoVra.Tests.ps1 b/Tests/Public/Get-ZertoVra.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoVra.Tests.ps1 +++ b/Tests/Public/Get-ZertoVra.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoZorg.Tests.ps1 b/Tests/Public/Get-ZertoZorg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoZorg.Tests.ps1 +++ b/Tests/Public/Get-ZertoZorg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Get-ZertoZsspSession.Tests.ps1 b/Tests/Public/Get-ZertoZsspSession.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Get-ZertoZsspSession.Tests.ps1 +++ b/Tests/Public/Get-ZertoZsspSession.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/New-ZertoVpg.Tests.ps1 b/Tests/Public/New-ZertoVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/New-ZertoVpg.Tests.ps1 +++ b/Tests/Public/New-ZertoVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 b/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 +++ b/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 b/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Remove-ZertoVpg.Tests.ps1 b/Tests/Public/Remove-ZertoVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Remove-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Remove-ZertoVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Remove-ZertoVpgSettingsIdentifier.Tests.ps1 b/Tests/Public/Remove-ZertoVpgSettingsIdentifier.Tests.ps1 index f5816b6..e6e6083 100644 --- a/Tests/Public/Remove-ZertoVpgSettingsIdentifier.Tests.ps1 +++ b/Tests/Public/Remove-ZertoVpgSettingsIdentifier.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { + + } + + Context "$global:function::Parameter Functional Tests" { - 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 } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Resume-ZertoVpg.Tests.ps1 b/Tests/Public/Resume-ZertoVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Resume-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Resume-ZertoVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 b/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 +++ b/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Set-ZertoAlert.Tests.ps1 b/Tests/Public/Set-ZertoAlert.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Set-ZertoAlert.Tests.ps1 +++ b/Tests/Public/Set-ZertoAlert.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Set-ZertoLicense.Tests.ps1 b/Tests/Public/Set-ZertoLicense.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Set-ZertoLicense.Tests.ps1 +++ b/Tests/Public/Set-ZertoLicense.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 b/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 +++ b/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 b/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 +++ b/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 b/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 +++ b/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 b/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 +++ b/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Suspend-ZertoVpg.Tests.ps1 b/Tests/Public/Suspend-ZertoVpg.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Suspend-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Suspend-ZertoVpg.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Uninstall-ZertoVra.Tests.ps1 b/Tests/Public/Uninstall-ZertoVra.Tests.ps1 index 50d2f9d..e6e6083 100644 --- a/Tests/Public/Uninstall-ZertoVra.Tests.ps1 +++ b/Tests/Public/Uninstall-ZertoVra.Tests.ps1 @@ -1,19 +1,17 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + + Context "$global:function::Parameter Unit Tests" { - 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 } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From 1e64d9d7f397828c922b7ababc3d1e3f2e8cc966 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 12:57:21 -0400 Subject: [PATCH 26/89] Renamed Function --- .../{New-Map.Tests.ps1 => Get-Map.Tests.ps1} | 20 +++++++++---------- .../Private/{New-Map.ps1 => Get-Map.ps1} | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) rename Tests/Private/{New-Map.Tests.ps1 => Get-Map.Tests.ps1} (79%) rename ZertoApiWrapper/Private/{New-Map.ps1 => Get-Map.ps1} (96%) diff --git a/Tests/Private/New-Map.Tests.ps1 b/Tests/Private/Get-Map.Tests.ps1 similarity index 79% rename from Tests/Private/New-Map.Tests.ps1 rename to Tests/Private/Get-Map.Tests.ps1 index 6134a02..8aeca06 100644 --- a/Tests/Private/New-Map.Tests.ps1 +++ b/Tests/Private/Get-Map.Tests.ps1 @@ -12,9 +12,9 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { it "Input Object should not accecpt a Null or Empty value" { $myObj = [PSCustomObject]@{ } - { New-Map -InputObject $myObj -Key "Key" -Value "Value" } | Should Throw - { New-Map -InputObject $null -Key "Key" -Value "Value" } | Should Throw - { New-Map -InputObject "" -Key "Key" -Value "Value" } | Should Throw + { Get-Map -InputObject $myObj -Key "Key" -Value "Value" } | Should Throw + { Get-Map -InputObject $null -Key "Key" -Value "Value" } | Should Throw + { Get-Map -InputObject "" -Key "Key" -Value "Value" } | Should Throw } it "have a mandatory string parameter for the Map Key" { @@ -23,16 +23,16 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { it "The Map variable should not accecpt a Null or Empty value" { $myObj = [PSCustomObject]@{one = 1; two = 2 } - { New-Map -InputObject $myObj -Key "" -Value "Value" } | Should Throw - { New-Map -InputObject $null -Key $null -Value "Value" } | Should Throw - { New-Map -InputObject $myObj -Key 1 -Value "Value" } | Should Throw + { Get-Map -InputObject $myObj -Key "" -Value "Value" } | Should Throw + { Get-Map -InputObject $null -Key $null -Value "Value" } | Should Throw + { Get-Map -InputObject $myObj -Key 1 -Value "Value" } | Should Throw } it "The Value variable should not accecpt a Null or Empty value" { $myObj = [PSCustomObject]@{one = 1; two = 2 } - { New-Map -InputObject $myObj -Key "Key" -Value "" } | Should Throw - { New-Map -InputObject $myObj -Key "Key" -Value $null } | Should Throw - { New-Map -InputObject $myObj -Key "Key" -Value 1 } | Should Throw + { Get-Map -InputObject $myObj -Key "Key" -Value "" } | Should Throw + { Get-Map -InputObject $myObj -Key "Key" -Value $null } | Should Throw + { Get-Map -InputObject $myObj -Key "Key" -Value 1 } | Should Throw } it "have a mandatory string parameter for the Map Value" { @@ -47,7 +47,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Function Tests" { $myObj = Get-Content "$global:here/Mocks/ProtectedVMs.json" | ConvertFrom-Json BeforeEach { - $MyMap = New-Map -InputObject $MyObj -Key "vmIdentifier" -Value "vmName" + $MyMap = Get-Map -InputObject $MyObj -Key "vmIdentifier" -Value "vmName" } it "Returned object should be a hashtable" { $myMap | Should -BeOfType Hashtable diff --git a/ZertoApiWrapper/Private/New-Map.ps1 b/ZertoApiWrapper/Private/Get-Map.ps1 similarity index 96% rename from ZertoApiWrapper/Private/New-Map.ps1 rename to ZertoApiWrapper/Private/Get-Map.ps1 index b84ea9d..343a711 100644 --- a/ZertoApiWrapper/Private/New-Map.ps1 +++ b/ZertoApiWrapper/Private/Get-Map.ps1 @@ -1,4 +1,4 @@ -function New-Map { +function Get-Map { [CmdletBinding()] [OutputType([Hashtable])] param( From 344e7836f9437805e18b1f3e588de155e06e8836 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 12:57:27 -0400 Subject: [PATCH 27/89] Update .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2f58130..be77f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *.zip temp/* -Tests/Public/TestResults.xml -Tests/TestResults.xml +BuiltTestResults.xml +SourceTestResults.xml publish/* CodeCoverage.xml From b11c497eadf6a66342374bdec8ca80ef9c922927 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 12:59:12 -0400 Subject: [PATCH 28/89] Update Exclude Rules --- ZertoApiWrapper.build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index b823443..197036c 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -52,7 +52,7 @@ task AnalyzeSourceFiles CheckPSScriptAnalyzerInstalled, { Severity = @('Error', 'Warning') Recurse = $true Verbose = $false - ExcludeRule = @('PSUseDeclaredVarsMoreThanAssignments', 'PSUseShouldProcessForStateChangingFunctions', 'PSUseToExportFieldsInManifest') + ExcludeRule = @('PSUseToExportFieldsInManifest', 'PSUseBOMForUnicodeEncodedFile', 'PSUseSingularNouns') } $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams if ($saResults) { @@ -67,7 +67,7 @@ task AnalyzeBuiltFiles CheckPSScriptAnalyzerInstalled, CreatePsm1ForRelease, { Severity = @('Error', 'Warning') Recurse = $true Verbose = $false - ExcludeRule = @("PSUseBOMForUnicodeEncodedFile", "PSUseSingularNouns") + ExcludeRule = @('PSUseSingularNouns', 'PSUseBOMForUnicodeEncodedFile') } $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams From 6a6b073adadb8a9e655f32b8e6c2dbf3607dade4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 13:00:28 -0400 Subject: [PATCH 29/89] Redirect Invoke Output to Null --- ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 b/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 index 4559701..b9d3032 100644 --- a/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 +++ b/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 @@ -5,7 +5,7 @@ function Disconnect-ZertoServer { $uri = "session" # Delete API Authorization - Invoke-ZertoRestRequest -uri $uri -method DELETE + $null = Invoke-ZertoRestRequest -uri $uri -method DELETE # Remove all variables used Remove-Variable -Name zvmServer -Scope Script From a526045662e1264196ff383ac20245530ebd3468 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 13:01:32 -0400 Subject: [PATCH 30/89] Update Map Function Call --- ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 | 4 ++-- ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 index 6de8852..bef7b42 100644 --- a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 @@ -38,12 +38,12 @@ function Export-ZertoVmNicSetting { } $nicSettings = foreach ($group in $vpgs) { $protectedVms = Get-ZertoProtectedVm -vpgName ($group.vpgname) - $vmMap = New-Map -InputObject $protectedVms -key "vmIdentifier" -value "vmName" + $vmMap = Get-Map -InputObject $protectedVms -key "vmIdentifier" -value "vmName" $settingsId = New-ZertoVpgSettingsIdentifier -vpgIdentifier $group.vpgIdentifier $vmSettings = Get-ZertoVpgSetting -vpgSettingsIdentifier $settingsId -vms $networks = Get-ZertoVirtualizationSite -siteIdentifier $group.RecoverySite.identifier -networks $null = Remove-ZertoVpgSettingsIdentifier -vpgSettingsIdentifier $settingsId - $networkMap = New-Map -InputObject $networks -key "NetworkIdentifier" -value "VirtualizationNetworkName" + $networkMap = Get-Map -InputObject $networks -key "NetworkIdentifier" -value "VirtualizationNetworkName" foreach ($vm in $vmSettings) { $nicInfo = [PSCustomObject]@{ VPGName = $group.VPGName diff --git a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 index 3cdf766..0a59888 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 @@ -31,9 +31,9 @@ function Import-ZertoVmNicSetting { $VpgInfo = Get-ZertoVpg -vpgName $Vpg $VpgIdentifier = $VpgInfo.VpgIdentifier $RecoveryNetworks = Get-ZertoVirtualizationSite -siteIdentifier $VpgInfo.RecoverySite.Identifier -networks - $NetworkMap = New-Map -InputObject $RecoveryNetworks -key "VirtualizationNetworkName" -value "NetworkIdentifier" + $NetworkMap = Get-Map -InputObject $RecoveryNetworks -key "VirtualizationNetworkName" -value "NetworkIdentifier" $VpgVms = Get-ZertoProtectedVm -vpgName $Vpg - $VmMap = New-Map -InputObject $VpgVms -key "vmName" -value "vmIdentifier" + $VmMap = Get-Map -InputObject $VpgVms -key "vmName" -value "vmIdentifier" $VpgSettingsId = New-ZertoVpgSettingsIdentifier -vpgIdentifier $VpgIdentifier $VmsToUpdate = $ImportData | Where-Object { $_.VPGName -eq $Vpg } foreach ($vm in $VmsToUpdate) { From a78f827804f10dcc6aed9498a7c3f674000feb28 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 13:48:25 -0400 Subject: [PATCH 31/89] Add Dhcp VRA Mock --- Tests/Public/Mocks/GetDhcpVra.json | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Tests/Public/Mocks/GetDhcpVra.json diff --git a/Tests/Public/Mocks/GetDhcpVra.json b/Tests/Public/Mocks/GetDhcpVra.json new file mode 100644 index 0000000..0c2539c --- /dev/null +++ b/Tests/Public/Mocks/GetDhcpVra.json @@ -0,0 +1,50 @@ +{ + "DatastoreClusterIdentifier": null, + "DatastoreClusterName": null, + "DatastoreIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.datastore-21", + "DatastoreName": "datastore1 (2)", + "HostIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.host-18", + "HostVersion": "6.7", + "IpAddress": "192.168.10.110", + "Link": { + "href": "https://192.168.10.20:9669/v1/vras/5377857665828094938", + "identifier": "5377857665828094938", + "rel": null, + "type": "VraApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vras/5377857665828094938", + "rel": "self", + "type": "VraApi" + }, + "MemoryInGB": 1, + "NetworkIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.network-22", + "NetworkName": "VM Network", + "Progress": 0, + "ProtectedCounters": { + "Vms": 0, + "Volumes": 0, + "Vpgs": 0 + }, + "RecoveryCounters": { + "Vms": 0, + "Volumes": 0, + "Vpgs": 0 + }, + "SelfProtectedVpgs": 0, + "Status": 0, + "VraAlerts": { + "VraAlertsStatus": 0 + }, + "VraGroup": "default_group", + "VraIdentifier": 5377857665828094938, + "VraIdentifierStr": "5377857665828094938", + "VraName": "Z-VRA-ncesx1.nc.lab", + "VraNetworkDataApi": { + "DefaultGateway": "", + "SubnetMask": "255.255.255.0", + "VraIPAddress": "192.168.10.110", + "VraIPConfigurationTypeApi": "Dhcp" + }, + "VraVersion": "7.0" +} From 9f2a6c42cd95b24d069b2d7b105496ea8664e26e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 13:49:03 -0400 Subject: [PATCH 32/89] Change error to Throw --- ZertoApiWrapper/Public/Edit-ZertoVra.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 index acf1693..1a0e40b 100644 --- a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 @@ -39,7 +39,7 @@ function Edit-ZertoVra { # Get the current VRA information for use if an updated parameter is not supplied $vra = Get-ZertoVra -vraIdentifier $vraIdentifier if ( -not $vra ) { - Write-Error "VRA with Identifier: $vraIdentifier could not be found. Please check the ID and try again." + Throw "VRA with Identifier: $vraIdentifier could not be found. Please check the ID and try again." } } @@ -87,4 +87,4 @@ function Edit-ZertoVra { # Nothing to Do } } -#TODO: Refactor \ No newline at end of file +#TODO: Refactor From a6d81aca44642ee98a356bace55787774f509f01 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 13:49:37 -0400 Subject: [PATCH 33/89] Refactor Tests --- Tests/Public/Edit-ZertoVra.Tests.ps1 | 226 ++++++++------------------- 1 file changed, 68 insertions(+), 158 deletions(-) diff --git a/Tests/Public/Edit-ZertoVra.Tests.ps1 b/Tests/Public/Edit-ZertoVra.Tests.ps1 index 4026b3d..ec609fd 100644 --- a/Tests/Public/Edit-ZertoVra.Tests.ps1 +++ b/Tests/Public/Edit-ZertoVra.Tests.ps1 @@ -1,187 +1,97 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest { - return "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f" + Get-Content $global:here\Mocks\TaskId.txt } - Mock -ModuleName ZertoApiWrapper Get-ZertoVra { - $vraInformation = @{ - DatastoreClusterIdentifier = $null - DatastoreClusterName = $null - DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore" - DatastoreName = "Prod_Datastore" - HostIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.znest82esxus-1" - HostVersion = 6.5 - IpAddress = 192.168.1.100 - Link = @{ - href = "https://192.168.1.200:7669/v1/vras/2609816293328110468" - identifier = "269816293328110468" - rel = $null - type = "VraApi" - } - MemoryInGB = 3 - NetworkIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.network-1" - NetworkName = "Test Network" - Progress = 0 - ProtectedCounters = @{ - Vms = 0 - Volumes = 0 - Vpgs = 0 - } - RecoveryCounters = @{ - Vms = 0 - Volumes = 0 - Vpgs = 0 - } - SelfProtectedVpgs = 0 - Status = 0 - VraAlerts = @{ - VraAlertStatus = 0 - } - VraGroup = "default_group" - VraIdentifier = 269816293328110468 - VraIdentifierStr = "269816293328110468" - VraName = "VRA-znest82esxus-1" - VraNetworkDataApi = @{ - DefaultGateway = "192.168.1.1" - SubnetMask = "255.255.255.0" - VraIpAddress = "192.168.1.100" - VraIpConfigurationTypeApi = "Dhcp" - } - VraVersion = 7.0 - } - return $vraInformation + Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "MyVraIdentifier" } { + Get-Content $global:here\Mocks\GetSingleVra.json -Raw | ConvertFrom-Json } - 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 + Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "DoesNotExist" } { + $null } - Context "$($File.BaseName)::Parameter Unit Tests" { + Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "DhcpVraIdentifier" } { + Get-Content $global:here\Mocks\GetDhcpVra.json -Raw | ConvertFrom-Json + } - It "has a mandatory String variable for the vraIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String - {Edit-ZertoVra} + Context "$($global:function)::Parameter Unit Tests" { + + $ParameterTestCases = @( + @{ParameterName = 'vraIdentifier'; Type = 'String'; Mandatory = $true } + @{ParameterName = 'groupName'; Type = 'String'; Mandatory = $false } + @{ParameterName = 'vraIpAddress'; Type = 'String'; Mandatory = $false } + @{ParameterName = 'defaultGateway'; Type = 'String'; Mandatory = $false } + @{ParameterName = 'subnetMask'; Type = 'String'; Mandatory = $false } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type } - It "has a non-mandatory String variable for the Bandwidth Group" { - Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter groupName -Type String + $StringTestCases = @( + @{ ParameterName = 'vraIdentifier' } + @{ ParameterName = 'groupName' } + ) + + it " validates against null or empty values" -TestCases $StringTestCases { + param($ParameterName) + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 } - it "has a non-mandatory String variable for the staticIp Address" { - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String - } + $IpAddrTestCases = @( + @{ParameterName = 'vraIpAddress' } + @{ParameterName = 'defaultGateway' } + @{ParameterName = 'subnetMask' } + ) - it "has a non-mandatory String variable for the default gateway" { - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String - } - - it "has a non-mandatory String variable for the subnetmask" { - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String - } - - it "supports WhatIf" { - Get-Command $file.BaseName | Should -HaveParameter WhatIf -Not -Mandatory - } - - $cases = ` - @{vraIpAddress = "192.168.1.256"}, ` - @{vraIpAddress = "192.168.1"}, ` - @{vraIpAddress = "String"}, ` - @{vraIpAddress = 192.168.1}, ` - @{vraIpAddress = 192.168.1.246}, ` - @{vraIpAddress = 32}, ` - @{vraIpAddress = ""}, ` - @{vraIpAddress = $null} - It "IpAddress field require valid IP addresses as a String" -TestCases $cases { - param ( $vraIpAddress ) - {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw - } - - $cases = ` - @{subnetMask = "192.168.1.256"}, ` - @{subnetMask = "192.168.1"}, ` - @{subnetMask = "String"}, ` - @{subnetMask = 192.168.1}, ` - @{subnetMask = 192.168.1.246}, ` - @{subnetMask = 32}, ` - @{subnetMask = ""}, ` - @{subnetMask = $null} - It "subnetMask field require valid IP addresses as a String" -TestCases $cases { - param ( $vraIpAddress ) - {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw - } - - $cases = ` - @{defaultGateway = "192.168.1.256"}, ` - @{defaultGateway = "192.168.1"}, ` - @{defaultGateway = "String"}, ` - @{defaultGateway = 192.168.1}, ` - @{defaultGateway = 192.168.1.246}, ` - @{defaultGateway = 32}, ` - @{defaultGateway = ""}, ` - @{defaultGateway = $null} - It "defaultGateway field require valid IP addresses as a String" -TestCases $cases { - param ( $vraIpAddress ) - {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw - } - - $cases = ` - @{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, ` - @{vraIdentifier = $null; paramName = "vraIdentifier"; paramValue = ""}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = $null}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = $null}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = $null}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}, ` - @{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = $null} - - It " does not take empty or null" -TestCases $cases { - param($vraIdentifier, $paramValue, $paramName ) - if ([String]::IsNullOrEmpty($vraIdentifier)) { - {Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw - } else { - {Edit-ZertoVra -vraIdentifier $vraIdentifier -$paramName $paramValue} | should -Throw - } + it " validates string for a valid IP Address" -TestCases $IpAddrTestCases { + param($ParameterName) + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1 + $attrs.Where{ $_ -is [ValidateScript] }.ScriptBlock | Should -Match '^\$_ \-match \[IPAddress\]\$_' } } - Context "$($File.BaseName)::Function Unit Tests" { + Context "$($global:function)::Function Unit Tests" { - It "Returns a string" { + It "Returns a task id string" { $results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup" $results | should not benullorempty $results | should -BeOfType "String" - $results | Should -BeExactly "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f" + $results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" + } + + It "Throws an error when the VPG does not exist" { + { Edit-ZertoVra -vraIdentifier "DoesNotExist" -groupName "MyNewGroup" } | Should Throw "VRA with Identifier:" + } + + It "Runs when passed static IP information" { + Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpAddress "192.168.1.250" -defaultGateway "192.168.1.254" -subnetMask "255.255.255.0" + } + + It "Processes a VRA with a DHCP address" { + Edit-ZertoVra -vraIdentifier "DhcpVraIdentifier" -groupName "MyNewGroup" | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" } it "Supports 'SupportsShouldProcess'" { - Get-Command $file.BaseName | Should -HaveParameter WhatIf - Get-Command $file.BaseName | Should -HaveParameter Confirm - $file | Should -FileContentMatch 'SupportsShouldProcess' - $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + Get-Command $global:function | Should -HaveParameter WhatIf + Get-Command $global:function | Should -HaveParameter Confirm + (Get-Command $global:function).ScriptBlock | Should -Match 'SupportsShouldProcess' + (Get-Command $global:function).ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)' } } - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra -} \ No newline at end of file + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 3 + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra -Exactly 4 +} + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 075a78436d4a5d29418e2a5900ac51d48dd2350e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 18:35:13 -0400 Subject: [PATCH 34/89] Add Mock Data Files --- Tests/Public/Mocks/GetVpg.json | 75 ++++++++ Tests/Public/Mocks/ProtectedVms.json | 274 +++++++++++++++++++++++++++ 2 files changed, 349 insertions(+) create mode 100644 Tests/Public/Mocks/GetVpg.json create mode 100644 Tests/Public/Mocks/ProtectedVms.json diff --git a/Tests/Public/Mocks/GetVpg.json b/Tests/Public/Mocks/GetVpg.json new file mode 100644 index 0000000..f1766dc --- /dev/null +++ b/Tests/Public/Mocks/GetVpg.json @@ -0,0 +1,75 @@ +{ + "ActiveProcessesApi": { + "RunningFailOverTestApi": null + }, + "ActualRPO": 7, + "BackupEnabled": false, + "ConfiguredRpoSeconds": 300, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "FailSafeHistory": { + "ActualFailSafeHistory": 60, + "ConfiguredFailSafeHistory": 240, + "FailSafeDescription": "" + }, + "HistoryStatusApi": { + "ActualHistoryInMinutes": 92, + "ConfiguredHistoryInMinutes": 1440, + "EarliestCheckpoint": { + "CheckpointIdentifier": "786", + "Tag": null, + "TimeStamp": "2019-07-20T19:30:19Z" + } + }, + "IOPs": 13, + "LastTest": null, + "Link": { + "href": "https://192.168.10.20:9669/v1/vpgs/57f502ff-3c41-4aff-b20a-6638205b73cd", + "identifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": null, + "type": "VpgApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vpgs/57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": "self", + "type": "VpgApi" + }, + "OrganizationName": "", + "Priority": 1, + "ProgressPercentage": 0, + "ProtectedSite": { + "href": "https://192.168.10.20:9669/v1/localsite", + "identifier": "9e09efa0-0d00-46ed-929b-f86273b28205", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 336118, + "RecoverySite": { + "href": "https://192.168.10.20:9669/v1/peersites/057cab27-f02a-443a-989d-7f14341fa9c3", + "identifier": "057cab27-f02a-443a-989d-7f14341fa9c3", + "rel": null, + "type": "PeerSiteApi" + }, + "ServiceProfile": null, + "ServiceProfileIdentifier": null, + "ServiceProfileName": "", + "SourceSite": "WCHL - NC", + "Status": 1, + "SubStatus": 0, + "TargetSite": "WCHL - CA", + "ThroughputInMB": 0.27197265625, + "UsedStorageInMB": 245465, + "VmsCount": 4, + "VpgIdentifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "VpgName": "ExportStuff", + "Zorg": { + "href": "https://192.168.10.20:9669/v1/zorgs/00000000-0000-0000-0000-000000000000", + "identifier": "00000000-0000-0000-0000-000000000000", + "rel": null, + "type": "ZorgApi" + } +} diff --git a/Tests/Public/Mocks/ProtectedVms.json b/Tests/Public/Mocks/ProtectedVms.json new file mode 100644 index 0000000..8326055 --- /dev/null +++ b/Tests/Public/Mocks/ProtectedVms.json @@ -0,0 +1,274 @@ +[ + { + "ActualRPO": 7, + "EnabledActions": { + "IsFlrEnabled": true + }, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "HardwareVersion": "vmx-15", + "IOPs": 2, + "IsVmExists": true, + "JournalHardLimit": { + "LimitType": 1, + "LimitValue": 153600 + }, + "JournalUsedStorageMb": 640, + "JournalWarningThreshold": { + "LimitType": 1, + "LimitValue": 115200 + }, + "LastTest": null, + "Link": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-38?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "identifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-38?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": null, + "type": "VmApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-38?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": "self", + "type": "VmApi" + }, + "OrganizationName": "", + "OutgoingBandWidthInMbps": 0.001953125, + "Priority": 1, + "ProtectedSite": { + "href": "https://192.168.10.20:9669/v1/localsite", + "identifier": "9e09efa0-0d00-46ed-929b-f86273b28205", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 77906, + "RecoveryHostIdentifier": "f45d81e4-4ff5-4376-a5c8-20ffe8d52431.host-15", + "RecoverySite": { + "href": "https://192.168.10.20:9669/v1/peersites/057cab27-f02a-443a-989d-7f14341fa9c3", + "identifier": "057cab27-f02a-443a-989d-7f14341fa9c3", + "rel": null, + "type": "PeerSiteApi" + }, + "SourceSite": "WCHL - NC", + "Status": 1, + "SubStatus": 0, + "TargetSite": "WCHL - CA", + "ThroughputInMB": 0, + "UsedStorageInMB": 77906, + "VmIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-38", + "VmName": "ncesx3.nc.lab", + "Volumes": [ + { + "VmVolumeIdentifier": "scsi:0:0" + } + ], + "VpgIdentifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "VpgName": "ExportStuff" + }, + { + "ActualRPO": 7, + "EnabledActions": { + "IsFlrEnabled": true + }, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "HardwareVersion": "vmx-15", + "IOPs": 1, + "IsVmExists": true, + "JournalHardLimit": { + "LimitType": 1, + "LimitValue": 153600 + }, + "JournalUsedStorageMb": 609, + "JournalWarningThreshold": { + "LimitType": 1, + "LimitValue": 115200 + }, + "LastTest": null, + "Link": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-37?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "identifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-37?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": null, + "type": "VmApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-37?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": "self", + "type": "VmApi" + }, + "OrganizationName": "", + "OutgoingBandWidthInMbps": 0.0009765625, + "Priority": 1, + "ProtectedSite": { + "href": "https://192.168.10.20:9669/v1/localsite", + "identifier": "9e09efa0-0d00-46ed-929b-f86273b28205", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 77906, + "RecoveryHostIdentifier": "f45d81e4-4ff5-4376-a5c8-20ffe8d52431.host-15", + "RecoverySite": { + "href": "https://192.168.10.20:9669/v1/peersites/057cab27-f02a-443a-989d-7f14341fa9c3", + "identifier": "057cab27-f02a-443a-989d-7f14341fa9c3", + "rel": null, + "type": "PeerSiteApi" + }, + "SourceSite": "WCHL - NC", + "Status": 1, + "SubStatus": 0, + "TargetSite": "WCHL - CA", + "ThroughputInMB": 0, + "UsedStorageInMB": 77906, + "VmIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-37", + "VmName": "ncesx2.nc.lab", + "Volumes": [ + { + "VmVolumeIdentifier": "scsi:0:0" + } + ], + "VpgIdentifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "VpgName": "ExportStuff" + }, + { + "ActualRPO": 7, + "EnabledActions": { + "IsFlrEnabled": true + }, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "HardwareVersion": "vmx-15", + "IOPs": 2, + "IsVmExists": true, + "JournalHardLimit": { + "LimitType": 1, + "LimitValue": 153600 + }, + "JournalUsedStorageMb": 634, + "JournalWarningThreshold": { + "LimitType": 1, + "LimitValue": 115200 + }, + "LastTest": null, + "Link": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-36?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "identifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-36?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": null, + "type": "VmApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-36?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": "self", + "type": "VmApi" + }, + "OrganizationName": "", + "OutgoingBandWidthInMbps": 0.00146484375, + "Priority": 1, + "ProtectedSite": { + "href": "https://192.168.10.20:9669/v1/localsite", + "identifier": "9e09efa0-0d00-46ed-929b-f86273b28205", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 77906, + "RecoveryHostIdentifier": "f45d81e4-4ff5-4376-a5c8-20ffe8d52431.host-15", + "RecoverySite": { + "href": "https://192.168.10.20:9669/v1/peersites/057cab27-f02a-443a-989d-7f14341fa9c3", + "identifier": "057cab27-f02a-443a-989d-7f14341fa9c3", + "rel": null, + "type": "PeerSiteApi" + }, + "SourceSite": "WCHL - NC", + "Status": 1, + "SubStatus": 0, + "TargetSite": "WCHL - CA", + "ThroughputInMB": 0, + "UsedStorageInMB": 77906, + "VmIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-36", + "VmName": "ncesx1.nc.lab", + "Volumes": [ + { + "VmVolumeIdentifier": "scsi:0:0" + } + ], + "VpgIdentifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "VpgName": "ExportStuff" + }, + { + "ActualRPO": 7, + "EnabledActions": { + "IsFlrEnabled": true + }, + "Entities": { + "Protected": 0, + "Recovery": 0, + "Source": 0, + "Target": 0 + }, + "HardwareVersion": "vmx-14", + "IOPs": 5, + "IsVmExists": true, + "JournalHardLimit": { + "LimitType": 1, + "LimitValue": 153600 + }, + "JournalUsedStorageMb": 642, + "JournalWarningThreshold": { + "LimitType": 1, + "LimitValue": 115200 + }, + "LastTest": null, + "Link": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-26?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "identifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-26?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": null, + "type": "VmApi" + }, + "Link_{0}": { + "href": "https://192.168.10.20:9669/v1/vms/d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-26?VpgIdentifier=57f502ff-3c41-4aff-b20a-6638205b73cd", + "rel": "self", + "type": "VmApi" + }, + "OrganizationName": "", + "OutgoingBandWidthInMbps": 0.01953125, + "Priority": 1, + "ProtectedSite": { + "href": "https://192.168.10.20:9669/v1/localsite", + "identifier": "9e09efa0-0d00-46ed-929b-f86273b28205", + "rel": null, + "type": "LocalSiteApi" + }, + "ProvisionedStorageInMB": 102400, + "RecoveryHostIdentifier": "f45d81e4-4ff5-4376-a5c8-20ffe8d52431.host-15", + "RecoverySite": { + "href": "https://192.168.10.20:9669/v1/peersites/057cab27-f02a-443a-989d-7f14341fa9c3", + "identifier": "057cab27-f02a-443a-989d-7f14341fa9c3", + "rel": null, + "type": "PeerSiteApi" + }, + "SourceSite": "WCHL - NC", + "Status": 1, + "SubStatus": 0, + "TargetSite": "WCHL - CA", + "ThroughputInMB": 0, + "UsedStorageInMB": 11747, + "VmIdentifier": "d4a6a1d5-79e9-4308-990a-7c3e616f0908.vm-26", + "VmName": "nczvm.nc.lab", + "Volumes": [ + { + "VmVolumeIdentifier": "scsi:0:0" + } + ], + "VpgIdentifier": "57f502ff-3c41-4aff-b20a-6638205b73cd", + "VpgName": "ExportStuff" + } +] From 55fb683dc315dd88a8ac9b68caa60ccaab016bde Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 19:18:46 -0400 Subject: [PATCH 35/89] Update Tests to TestCases --- .../Public/Export-ZertoVmNicSetting.Tests.ps1 | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/Tests/Public/Export-ZertoVmNicSetting.Tests.ps1 b/Tests/Public/Export-ZertoVmNicSetting.Tests.ps1 index 7e63113..be52ffb 100644 --- a/Tests/Public/Export-ZertoVmNicSetting.Tests.ps1 +++ b/Tests/Public/Export-ZertoVmNicSetting.Tests.ps1 @@ -1,42 +1,32 @@ #Requires -Modules Pester -#Region - Test Setup -$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 -#EndRegion +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 + Context "$global:function::Parameter Unit Tests" { + + $ParameterTestCases = @( + @{ParameterName = 'OutputFile'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + it " has validation set" -TestCases $ParameterTestCases { + param($ParameterName) + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } } - Context "$($file.BaseName)::Parameter Unit Tests" { - It "has a mantatory string parameter for the output file" { - Get-Command $file.BaseName | Should -HaveParameter OutputFile -Type String -Mandatory - } - - It "has a non-mandatory string array parameter for vpgName(s) to export" { - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Not -Mandatory - } - - It "Output File does not take null or empty string" { - { Export-ZertoVpg -outputFile "" } | Should -Throw - { Export-ZertoVpg -outputFile $null } | Should -Throw - } - - It "Vpg Name parameter does not take null or empty string" { - { Export-ZertoVpg -outputFile ".\ExportedInfo.csv" -vpgName = "" } | Should -Throw - { Export-ZertoVpg -outputFile ".\ExportedInfo.csv" -vpgName = $null } | Should -Throw - } + Context "$global:function::Function Unit Tests" { + } } + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 213329801af8f52fdfb4ba60e9aef8fb2721ccee Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 19:42:48 -0400 Subject: [PATCH 36/89] Update Tests to New Format --- Tests/Public/Export-ZertoVpg.Tests.ps1 | 69 +++++++++++--------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/Tests/Public/Export-ZertoVpg.Tests.ps1 b/Tests/Public/Export-ZertoVpg.Tests.ps1 index e46b59e..e733e93 100644 --- a/Tests/Public/Export-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Export-ZertoVpg.Tests.ps1 @@ -1,53 +1,39 @@ #Requires -Modules Pester -#Region - Test Setup -$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 -#EndRegion +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { - it "has a mantatory string parameter for the output path" { - Get-Command $file.BaseName | Should -HaveParameter outputPath -Type String -Mandatory + $ParameterTestCases = @( + @{ParameterName = 'OutputPath'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'allVpgs'; Type = 'Switch'; Mandatory = $true; Validation = $null } + ) + + It " parameter is of type, with correct validation" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type } - it "has a non-mandatory string array parameter for vpgName(s) to export" { - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] -Mandatory - } + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } - it "has a non-mandatory switch parameter to export all vpgs" { - Get-Command $file.BaseName | Should -HaveParameter allVpgs -Type Switch -Mandatory - } - - it "No defined vpgName or AllVpg switch should throw an error" { - {Export-ZertoVpg -outputPath "."} | Should -Throw - } - - it "Output path does not take null or empty string" { - {Export-ZertoVpg -outputPath "" -allVpgs} | Should -Throw - {Export-ZertoVpg -outputPath $null -allVpgs} | Should -Throw - } - - it "Vpg Name parameter does not take null or empty string" { - {Export-ZertoVpg -outputPath "." -vpgName = ""} | Should -Throw - {Export-ZertoVpg -outputPath "." -vpgName = $null} | Should -Throw + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + } } } - Context "$($file.BaseName)::Function Unit Tests" { + Context "$($global:function)::Function Unit Tests" { Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg { $returnObj = @{ VpgName = "HRIS" @@ -247,3 +233,6 @@ Describe $file.BaseName -Tag 'Unit' { Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting } } + +Remove-Variable -Name function -Scope Global +Remove-Variable -Name here -Scope Global From 6b1486b74d5b62b45fa8c4bf6694a609723a09e9 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 19:58:48 -0400 Subject: [PATCH 37/89] Update Tests to new format --- Tests/Public/Get-ZertoAlert.Tests.ps1 | 118 ++++++++++---------------- 1 file changed, 43 insertions(+), 75 deletions(-) diff --git a/Tests/Public/Get-ZertoAlert.Tests.ps1 b/Tests/Public/Get-ZertoAlert.Tests.ps1 index d3e1558..39873fd 100644 --- a/Tests/Public/Get-ZertoAlert.Tests.ps1 +++ b/Tests/Public/Get-ZertoAlert.Tests.ps1 @@ -1,84 +1,52 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 + Context "$global:function::Parameter Unit Tests" { + + $ParameterTestCases = @( + @{ParameterName = 'alertId'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'entities'; Type = 'Switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'helpIdentifiers'; Type = 'Switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'levels'; Type = 'Switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'level'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'helpIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'isDismissed'; Type = 'bool'; Mandatory = $false; Validation = $null } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + } + } } - Context "$($file.BaseName)::Parameter Unit Tests" { + Context "$global:function::Parameter Functional Tests" { - it "Has a mandatory string parameter for the Alert identifier" { - Get-Command $file.BaseName | Should -HaveParameter alertId - Get-Command $file.BaseName | Should -HaveParameter alertId -Mandatory - Get-Command $file.BaseName | Should -HaveParameter alertId -Type String[] - } - - it "Has a non-mandatory switch parameter for the entities" { - Get-Command $file.BaseName | Should -HaveParameter entities - Get-Command $file.BaseName | Should -HaveParameter entities -Type switch - } - - it "Has a non-mandatory switch parameter for the helpIdentifiers" { - Get-Command $file.BaseName | Should -HaveParameter helpIdentifiers - Get-Command $file.BaseName | Should -HaveParameter helpIdentifiers -Type switch - } - - it "Has a non-mandatory switch parameter for the levels" { - Get-Command $file.BaseName | Should -HaveParameter levels - Get-Command $file.BaseName | Should -HaveParameter levels -Type switch - } - - it "Has a non-mandatory string parameter for the startDate" { - Get-Command $file.BaseName | Should -HaveParameter startDate - Get-Command $file.BaseName | Should -HaveParameter startDate -Type string - } - - it "Has a non-mandatory string parameter for the endDate" { - Get-Command $file.BaseName | Should -HaveParameter endDate - Get-Command $file.BaseName | Should -HaveParameter endDate -Type string - } - - it "Has a non-mandatory string parameter for the vpgIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter vpgIdentifier - Get-Command $file.BaseName | Should -HaveParameter vpgIdentifier -Type string - } - - it "Has a non-mandatory string parameter for the siteIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter siteIdentifier - Get-Command $file.BaseName | Should -HaveParameter siteIdentifier -Type string - } - - it "Has a non-mandatory string parameter for the zorgIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter zorgIdentifier - Get-Command $file.BaseName | Should -HaveParameter zorgIdentifier -Type string - } - - it "Has a non-mandatory string parameter for the level" { - Get-Command $file.BaseName | Should -HaveParameter level - Get-Command $file.BaseName | Should -HaveParameter level -Type string - } - - it "Has a non-mandatory string parameter for the helpIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter helpIdentifier - Get-Command $file.BaseName | Should -HaveParameter helpIdentifier -Type string - } - - it "Has a non-mandatory bool parameter for the isDismissed" { - Get-Command $file.BaseName | Should -HaveParameter isDismissed - Get-Command $file.BaseName | Should -HaveParameter isDismissed -Type bool - } } } +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global + From 047e701f5527061d70544d16f554d60180a51526 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:01:02 -0400 Subject: [PATCH 38/89] Update tests to new format --- Tests/Public/Get-ZertoAlert.Tests.ps1 | 1 - Tests/Public/Get-ZertoDatastore.Tests.ps1 | 33 +++++++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Tests/Public/Get-ZertoAlert.Tests.ps1 b/Tests/Public/Get-ZertoAlert.Tests.ps1 index 39873fd..8f3c29b 100644 --- a/Tests/Public/Get-ZertoAlert.Tests.ps1 +++ b/Tests/Public/Get-ZertoAlert.Tests.ps1 @@ -49,4 +49,3 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Remove-Variable -Name here -Scope Global Remove-Variable -Name function -Scope Global - diff --git a/Tests/Public/Get-ZertoDatastore.Tests.ps1 b/Tests/Public/Get-ZertoDatastore.Tests.ps1 index 294021f..46c470b 100644 --- a/Tests/Public/Get-ZertoDatastore.Tests.ps1 +++ b/Tests/Public/Get-ZertoDatastore.Tests.ps1 @@ -1,24 +1,21 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 + Context "$global:function::Parameter Unit Tests" { + + It "has a non-mandatory string parameter for the datacenterIdentifier" { + Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier + Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier -Type String[] + } } - It "has a non-mandatory string parameter for the datacenterIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier - Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier -Type String[] + Context "$global:function::Parameter Functional Tests" { + } -} \ No newline at end of file +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From 3e3a4338433db45bfa8ce7818f7673ddd6a8fe06 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:03:06 -0400 Subject: [PATCH 39/89] Update tests to new format --- Tests/Public/Get-ZertoLocalSite.Tests.ps1 | 31 +++++++++-------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 index 03ae2c6..4412139 100644 --- a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 @@ -1,27 +1,20 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 - } - - Context "$($file.BaseName)::Parameter Unit Tests" { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + Context "$global:function::Parameter Unit Tests" { it "Has a non-mandatory switch parameter for the pairing Statuses" { Get-Command $file.BaseName | Should -HaveParameter pairingstatuses Get-Command $file.BaseName | Should -HaveParameter pairingstatuses -Type switch } } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From b82912605e68f6a2719348ee1f491f85d63aabb5 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:07:02 -0400 Subject: [PATCH 40/89] Update tests to new format --- .../Public/Import-ZertoVmNicSetting.Tests.ps1 | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 b/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 index 5647976..a499b6a 100644 --- a/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 +++ b/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 @@ -1,39 +1,26 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 - } - - Context "$($file.BaseName)::Parameter Unit Tests" { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + Context "$global:function::Parameter Unit Tests" { It "Has a mandatory string array parameter for the settings file to import" { - Get-Command $file.BaseName | Should -HaveParameter InputFile - Get-Command $file.BaseName | Should -HaveParameter InputFile -Mandatory - Get-Command $file.BaseName | Should -HaveParameter InputFile -Type String + Get-Command $global:function | Should -HaveParameter InputFile + Get-Command $global:function | Should -HaveParameter InputFile -Mandatory + Get-Command $global:function | Should -HaveParameter InputFile -Type String } It "Will not accecpt a Null or Empty string for the settings file" { - { Import-ZertoVpg -InputFile $null } | Should -Throw - { Import-ZertoVpg -InputFile "" } | Should -Throw - { Import-ZertoVpg -InputFile @() } | Should -Throw + $attrs = (Get-Command $global:function).Parameters['InputFile'].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 } - } - Context "$($file.BaseName)::Function Unit Tests" { + Context "$global:function::Parameter Functional Tests" { } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From ff54a92f92005d198995d71358cfa6794b4917c8 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:10:06 -0400 Subject: [PATCH 41/89] Fix function call var --- Tests/Public/Get-ZertoDatastore.Tests.ps1 | 4 ++-- Tests/Public/Get-ZertoLocalSite.Tests.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Public/Get-ZertoDatastore.Tests.ps1 b/Tests/Public/Get-ZertoDatastore.Tests.ps1 index 46c470b..6727a99 100644 --- a/Tests/Public/Get-ZertoDatastore.Tests.ps1 +++ b/Tests/Public/Get-ZertoDatastore.Tests.ps1 @@ -7,8 +7,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { It "has a non-mandatory string parameter for the datacenterIdentifier" { - Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier - Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier -Type String[] + Get-Command $global:function | Should -HaveParameter datastoreIdentifier + Get-Command $global:function | Should -HaveParameter datastoreIdentifier -Type String[] } } diff --git a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 index 4412139..4fea226 100644 --- a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 @@ -6,8 +6,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { it "Has a non-mandatory switch parameter for the pairing Statuses" { - Get-Command $file.BaseName | Should -HaveParameter pairingstatuses - Get-Command $file.BaseName | Should -HaveParameter pairingstatuses -Type switch + Get-Command $global:function | Should -HaveParameter pairingstatuses + Get-Command $global:function | Should -HaveParameter pairingstatuses -Type switch } } From c05a5279826ca7731ff2c1cf812a7b7c45623e2f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:14:58 -0400 Subject: [PATCH 42/89] Update tests to new format --- Tests/Public/Import-ZertoVpg.Tests.ps1 | 39 +++++++++----------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/Tests/Public/Import-ZertoVpg.Tests.ps1 b/Tests/Public/Import-ZertoVpg.Tests.ps1 index bd91e77..4fd59b3 100644 --- a/Tests/Public/Import-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Import-ZertoVpg.Tests.ps1 @@ -1,39 +1,26 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -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 - } - - Context "$($file.BaseName)::Parameter Unit Tests" { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { + Context "$global:function::Parameter Unit Tests" { It "Has a mandatory string array parameter for the settings file to import" { - Get-Command $file.BaseName | Should -HaveParameter settingsFile - Get-Command $file.BaseName | Should -HaveParameter settingsFile -Mandatory - Get-Command $file.BaseName | Should -HaveParameter settingsFile -Type String[] + Get-Command $global:function | Should -HaveParameter settingsFile + Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory + Get-Command $global:function | Should -HaveParameter settingsFile -Type String[] } It "Will not accecpt a Null or Empty string for the settings file" { - {Import-ZertoVpg -settingsFile $null} | Should -Throw - {Import-ZertoVpg -settingsFile ""} | Should -Throw - {Import-ZertoVpg -settingsFile @()} | Should -Throw + $attrs = (Get-Command $global:function).Parameters['settingsFile'].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 } - } - Context "$($file.BaseName)::Function Unit Tests" { + Context "$global:function::Parameter Functional Tests" { } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From 37016076fde9c710f5bd67a1a9bdc0ed4b75839c Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 20 Jul 2019 20:56:23 -0400 Subject: [PATCH 43/89] Update to the new format --- Tests/Public/Install-ZertoVra.Tests.ps1 | 143 ++++++-------------- Tests/Public/Invoke-ZertoFailover.Tests.ps1 | 124 +++++++++-------- 2 files changed, 113 insertions(+), 154 deletions(-) diff --git a/Tests/Public/Install-ZertoVra.Tests.ps1 b/Tests/Public/Install-ZertoVra.Tests.ps1 index 598a6e4..e14e10f 100644 --- a/Tests/Public/Install-ZertoVra.Tests.ps1 +++ b/Tests/Public/Install-ZertoVra.Tests.ps1 @@ -1,108 +1,51 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 + Context "$global:function::Parameter Unit Tests" { + $ParameterTestCases = @( + @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'networkName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'Dhcp'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'vraIpAddress'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' } + @{ParameterName = 'subnetMask'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' } + @{ParameterName = 'defaultGateway'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'IpAddr' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1 + $attrs.Where{ $_ -is [ValidateScript] }.ScriptBlock | Should -Match '^\$_ \-match \[IPAddress\]\$_' + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + } + } } - Context "$($file.BaseName)::Parameter Unit Tests" { + Context "$global:function::Parameter Functional Tests" { - It "Has a mandatory string host name parameter" { - Get-Command $file.BaseName | Should -HaveParameter hostName - Get-Command $file.BaseName | Should -HaveParameter hostName -Mandatory - Get-Command $file.BaseName | Should -HaveParameter hostName -Type String - } - - It "Will not accecpt a Null or Empty string for the host name" { - {Install-ZertoVra -hostName $null -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" - {Install-ZertoVra -hostName "" -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" - } - - It "Has a mandatory string datastore parameter" { - Get-Command $file.BaseName | Should -HaveParameter datastoreName - Get-Command $file.BaseName | Should -HaveParameter datastoreName -Mandatory - Get-Command $file.BaseName | Should -HaveParameter datastoreName -Type String - } - - It "Will not accecpt a Null or Empty string for the datastore" { - {Install-ZertoVra -hostName "MyfirstHost" -datastoreName $null -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" - {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" - } - - It "Has a mandatory string network parameter" { - Get-Command $file.BaseName | Should -HaveParameter networkName - Get-Command $file.BaseName | Should -HaveParameter networkName -Mandatory - Get-Command $file.BaseName | Should -HaveParameter networkName -Type String - } - - It "Will not accecpt a Null or Empty string for the datastore" { - {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName $null -Dhcp } | Should -Throw "The argument is null or empty" - {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName "" -Dhcp } | Should -Throw "The argument is null or empty" - } - - it "Has a switch parameter for setting DHCP" { - Get-Command $file.BaseName | Should -HaveParameter Dhcp - Get-Command $file.BaseName | Should -HaveParameter Dhcp -Mandatory - Get-Command $file.BaseName | Should -HaveParameter Dhcp -Type 'Switch' - - } - - it "Has a mandatory string parameter for the static IP address" { - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Mandatory - Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String - } - - it "Has a mandatory string parameter for the subnet mask" { - Get-Command $file.BaseName | Should -HaveParameter subnetMask - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Mandatory - Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String - } - - it "Has a mandatory string parameter for the default gateway" { - Get-Command $file.BaseName | Should -HaveParameter defaultGateway - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Mandatory - Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String - } - - $cases = ` - @{invalidIpAddress = "192.168.1.256"}, ` - @{invalidIpAddress = "192.168.1"}, ` - @{invalidIpAddress = "String"}, ` - @{invalidIpAddress = 192.168.1.246}, ` - @{invalidIpAddress = 32}, ` - @{invalidIpAddress = ""}, ` - @{invalidIpAddress = $null} - It "IpAddress field require valid IP addresses as a String: " -TestCases $cases { - param ( $invalidIpAddress ) - {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress $invalidIpAddress -subnetMask "255.255.255.0" -defaultGateway "192.168.1.254"} | Should -Throw - } - - It "Default Gateway field require valid IP addresses as a String: " -TestCases $cases { - param ( $invalidIpAddress ) - {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask "255.255.255.0" -defaultGateway $invalidIpAddress} | Should -Throw - } - - It "Subnet Mask field require valid IP addresses as a String: " -TestCases $cases { - param ( $invalidIpAddress ) - {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask $invalidIpAddress -defaultGateway "192.168.1.254"} | Should -Throw - } - - } - - Context "$($file.BaseName)::Function Unit Tests" { - #TODO } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 index 8582291..fab5802 100644 --- a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 @@ -1,77 +1,93 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { + $ParameterTestCases = @( + @{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'checkpointIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'commitPolicy'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'shutdownPolicy'; Type = 'Int'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'timeToWaitBeforeShutdownInSec'; Type = 'Int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'reverseProtection'; Type = 'bool'; Mandatory = $false; Validation = $null } + @{ParameterName = 'vmName'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' } + ) - Context "$($file.BaseName)::Parameter Unit Tests" { - it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type } - it "has a non-mandatory string parameter for the checkpoint" { - Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier - Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Type string - Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Not -Mandatory + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Set' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + 'Range' { + $scriptBlock = (Get-Command $global:function).ScriptBlock + $scriptBlock | Should -match 'SupportsShouldProcess' + $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + } } - it "has a non-mandatory string parameter for the commit policy" { - Get-Command $file.BaseName | Should -HaveParameter commitPolicy - Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Type string - Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter commitPolicy -DefaultValue "Rollback" + It "Commit Policy Default Value is 'RollBack'" { + Get-Command $global:function | Should -HaveParameter commitPolicy -DefaultValue "Rollback" } - it "has a non-mandatory int parameter for the shutdown policy" { - Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy - Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Type int - Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -DefaultValue 0 + It "Commit Policy Only Accecpts 'RollBack', 'Commit', or 'None'" { + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3 + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'RollBack' + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Commit' + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'None' } - it "has a non-mandatory int parameter for the time to wait before force shutdown" { - Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec - Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Type int - Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Not -Mandatory - Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -DefaultValue 3600 + It "Shutdown Policy Default Value is '0'" { + Get-Command $global:function | Should -HaveParameter shutdownPolicy -DefaultValue 0 } - it "has a non-mandatory bool parameter for the reverse protection policy" { - Get-Command $file.BaseName | Should -HaveParameter reverseProtection - Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type bool - Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Not -Mandatory + It "Shutdown Policy Only Accecpts 'RollBack', 'Commit', or 'None'" { + (Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3 + (Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 0 + (Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 1 + (Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 2 } - it "has a non-mandatory array string parameter for the named VMs to be failed over" { - Get-Command $file.BaseName | Should -HaveParameter vmName - Get-Command $file.BaseName | Should -HaveParameter vmName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vmName -Not -Mandatory + it "Time to wait before shutdown in sec should have a default value of 3600" { + Get-Command $global:function | Should -HaveParameter timeToWaitBeforeShutdownInSec -DefaultValue 3600 } - it "Supports 'SupportsShouldProcess'" { - Get-Command $file.BaseName | Should -HaveParameter WhatIf - Get-Command $file.BaseName | Should -HaveParameter Confirm - $file | Should -FileContentMatch 'SupportsShouldProcess' - $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + it "Time to wait before shutdown in sec should have a minimum value of 300 and max value of 86400" { + (Get-Command $global:function).Parameters['timeToWaitBeforeShutdownInSec'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 300 + (Get-Command $global:function).Parameters['timeToWaitBeforeShutdownInSec'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 86400 } } - Context "$($file.BaseName)::Function Unit Tests" { - #TODO + Context "$global:function::Parameter Functional Tests" { + } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From a39f2638d1245a14373877f7628eae63ed612f70 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:36:30 -0400 Subject: [PATCH 44/89] Update to new test format --- .../Invoke-ZertoFailoverCommit.Tests.ps1 | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 index 2fa2e2e..aec697f 100644 --- a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 @@ -1,44 +1,56 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { - - it "Supports 'ShouldProcess'" { - Get-Command $file.BaseName | Should -HaveParameter WhatIf - Get-Command $file.BaseName | Should -HaveParameter Confirm - $file | Should -FileContentMatch 'SupportsShouldProcess' - $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 } - it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + $ParameterTestCases = @( + @{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'reverseProtection'; Type = 'switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type } - it "has a switch parameter for reverse protection" { - Get-Command $file.BaseName | Should -HaveParameter reverseProtection - Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type switch + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'ShouldProcess' { + $scriptBlock = (Get-Command $global:function).ScriptBlock + $scriptBlock | Should -match 'SupportsShouldProcess' + $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } } } - Context "$($file.BaseName)::Function Unit Tests" { - #TODO + Context "$global:function::Parameter Functional Tests" { + } } + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From 5213614299aae9f85202c099cf5ceec6bc405d3f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:36:46 -0400 Subject: [PATCH 45/89] Add Parameter count test --- Tests/Public/Import-ZertoVpg.Tests.ps1 | 4 ++++ Tests/Public/Install-ZertoVra.Tests.ps1 | 4 ++++ Tests/Public/Invoke-ZertoFailover.Tests.ps1 | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Import-ZertoVpg.Tests.ps1 b/Tests/Public/Import-ZertoVpg.Tests.ps1 index 4fd59b3..f0f8969 100644 --- a/Tests/Public/Import-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Import-ZertoVpg.Tests.ps1 @@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 12 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 12 + } + It "Has a mandatory string array parameter for the settings file to import" { Get-Command $global:function | Should -HaveParameter settingsFile Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory diff --git a/Tests/Public/Install-ZertoVra.Tests.ps1 b/Tests/Public/Install-ZertoVra.Tests.ps1 index e14e10f..03cb03d 100644 --- a/Tests/Public/Install-ZertoVra.Tests.ps1 +++ b/Tests/Public/Install-ZertoVra.Tests.ps1 @@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 22 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 22 + } + $ParameterTestCases = @( @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } diff --git a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 index fab5802..11dd2f9 100644 --- a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 @@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 20 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 20 + } + $ParameterTestCases = @( @{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'checkpointIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } @@ -39,7 +43,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 } - 'Range' { + 'ShouldProcess' { $scriptBlock = (Get-Command $global:function).ScriptBlock $scriptBlock | Should -match 'SupportsShouldProcess' $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' @@ -49,6 +53,10 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes $attrs.TypeId.Count | Should -Be 2 } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } } } From 6df14f7a8d9b551e64639fa860a2f24549765f41 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:49:08 -0400 Subject: [PATCH 46/89] Parameter Count Test --- Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 b/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 index a499b6a..ce84a86 100644 --- a/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 +++ b/Tests/Public/Import-ZertoVmNicSetting.Tests.ps1 @@ -5,6 +5,10 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 11 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + It "Has a mandatory string array parameter for the settings file to import" { Get-Command $global:function | Should -HaveParameter InputFile Get-Command $global:function | Should -HaveParameter InputFile -Mandatory From 202c865fe8e04050b55df8f0096b59abe255e8ec Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:54:28 -0400 Subject: [PATCH 47/89] Update tests to new format --- .../Invoke-ZertoFailoverRollback.Tests.ps1 | 37 +++++++++--------- Tests/Public/Invoke-ZertoForceSync.Tests.ps1 | 38 +++++++++---------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 index 89cf63f..28f1eb7 100644 --- a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 @@ -1,28 +1,25 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 12 + } it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + Get-Command $global:function | Should -HaveParameter vpgName + Get-Command $global:function | Should -HaveParameter vpgName -Type string[] + Get-Command $global:function | Should -HaveParameter vpgName -Mandatory } } -} \ No newline at end of file + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 index 89cf63f..2e6830d 100644 --- a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 @@ -1,28 +1,26 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 12 + } it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + Get-Command $global:function | Should -HaveParameter vpgName + Get-Command $global:function | Should -HaveParameter vpgName -Type string[] + Get-Command $global:function | Should -HaveParameter vpgName -Mandatory } } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From e1720dd4f772b5fa3a173a33d4d07c8697d8be86 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 11:56:03 -0400 Subject: [PATCH 48/89] Update test description --- Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 | 2 +- Tests/Public/Invoke-ZertoForceSync.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 index 28f1eb7..84109bd 100644 --- a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 @@ -6,7 +6,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "$global:function should have exactly 15 parameters defined" { + it "$global:function should have exactly 12 parameters defined" { (get-command $global:function).Parameters.Count | Should -Be 12 } diff --git a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 index 2e6830d..159e825 100644 --- a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 @@ -6,7 +6,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "$global:function should have exactly 15 parameters defined" { + it "$global:function should have exactly 12 parameters defined" { (get-command $global:function).Parameters.Count | Should -Be 12 } From 928d6ef4a1be7c5e89db175bac1e245f944c3967 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 12:09:15 -0400 Subject: [PATCH 49/89] Update tests to new format --- Tests/Public/Invoke-ZertoMove.Tests.ps1 | 130 +++++++++++++----------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/Tests/Public/Invoke-ZertoMove.Tests.ps1 b/Tests/Public/Invoke-ZertoMove.Tests.ps1 index abfb900..6217a52 100644 --- a/Tests/Public/Invoke-ZertoMove.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMove.Tests.ps1 @@ -1,74 +1,82 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } - - Context "$($file.BaseName)::Parameter Unit Tests" { - - it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 20 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 20 } - it "has a non-mandatory string parameter for commitPolicy" { - Get-Command $file.BaseName | Should -HaveParameter commitPolicy - Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Type string + $ParameterTestCases = @( + @{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'commitPolicy'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'commitPolicyTimeout'; Type = 'Int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'forceShutdown'; Type = 'Switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'disableReverseProtection'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'keepSourceVms'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'ContinueOnPreScriptFailure'; Type = 'Switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type } - it "CommitPolicy only accecpts 'Rollback', 'Commit', or 'None'" { - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy "Rollbackk" } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy "" } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy $null } | Should -Throw + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Set' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + 'ShouldProcess' { + $scriptBlock = (Get-Command $global:function).ScriptBlock + $scriptBlock | Should -match 'SupportsShouldProcess' + $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } } - it "has a non-mandatory int parameter for commitPolicyTimeout" { - Get-Command $file.BaseName | Should -HaveParameter commitPolicyTimeout - Get-Command $file.BaseName | Should -HaveParameter commitPolicyTimeout -Type Int + It "Commit Policy Only Accecpts 'RollBack', 'Commit', or 'None'" { + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3 + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'RollBack' + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Commit' + (Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'None' } - it "Commit Policy Timeout will only accecpt an int value between 5 minutes and 24 Hours" { - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout 150 } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout 15000000 } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout -1350 } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout $null } | Should -Throw - { Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout "" } | Should -Throw - } - - it "has a non-mandatory switch parameter for forceShutdown" { - Get-Command $file.BaseName | Should -HaveParameter forceShutdown - Get-Command $file.BaseName | Should -HaveParameter forceShutdown -Type Switch - } - - it "has a mandatory switch parameter for disableReverseProtection" { - Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection - Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection -Type Switch - Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection -Mandatory - } - - it "has a non-mandatory switch parameter for keepSourceVms" { - Get-Command $file.BaseName | Should -HaveParameter keepSourceVms - Get-Command $file.BaseName | Should -HaveParameter keepSourceVms -Type Switch - Get-Command $file.BaseName | Should -HaveParameter keepSourceVms -Mandatory - } - - it "has a non-mandatory switch parameter for ContinueOnPreScriptFailure" { - Get-Command $file.BaseName | Should -HaveParameter ContinueOnPreScriptFailure - Get-Command $file.BaseName | Should -HaveParameter ContinueOnPreScriptFailure -Type Switch + it "Commit Policy Timeout should have a minimum value of 300 and max value of 86400" { + (Get-Command $global:function).Parameters['commitPolicyTimeout'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 300 + (Get-Command $global:function).Parameters['commitPolicyTimeout'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 86400 } } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From 9be00e68b1fd3dd1bea5092d932af0a8b484b252 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 12:17:33 -0400 Subject: [PATCH 50/89] Update to new test format --- .../Invoke-ZertoFailoverCommit.Tests.ps1 | 4 +- Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 | 70 +++++++++++++------ .../Public/Invoke-ZertoMoveRollback.Tests.ps1 | 37 +++++----- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 index aec697f..b8abfd8 100644 --- a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 @@ -6,8 +6,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "$global:function should have exactly 15 parameters defined" { - (get-command $global:function).Parameters.Count | Should -Be 15 + it "$global:function should have exactly 16 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 16 } $ParameterTestCases = @( diff --git a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 index 89cf63f..aec697f 100644 --- a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 @@ -1,28 +1,56 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } - it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + $ParameterTestCases = @( + @{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'reverseProtection'; Type = 'switch'; Mandatory = $false; Validation = $null } + @{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'ShouldProcess' { + $scriptBlock = (Get-Command $global:function).ScriptBlock + $scriptBlock | Should -match 'SupportsShouldProcess' + $scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)' + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } } } -} \ No newline at end of file + + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global diff --git a/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 b/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 index 89cf63f..53c3383 100644 --- a/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 @@ -1,28 +1,25 @@ #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 +$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path) +$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0] -Describe $file.BaseName -Tag 'Unit' { +Describe $global:function -Tag 'Unit', 'Source', 'Built' { - 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 - } + Context "$global:function::Parameter Unit Tests" { - Context "$($file.BaseName)::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } it "has a mandatory string parameter for the vpgName" { - Get-Command $file.BaseName | Should -HaveParameter vpgName - Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[] - Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + Get-Command $global:function | Should -HaveParameter vpgName + Get-Command $global:function | Should -HaveParameter vpgName -Type string[] + Get-Command $global:function | Should -HaveParameter vpgName -Mandatory } } -} \ No newline at end of file + Context "$global:function::Parameter Functional Tests" { + + } +} + +Remove-Variable -Name here -Scope Global +Remove-Variable -Name function -Scope Global From efea4944755c5d604f66ded5cb5c27348ab79fe2 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 12:23:27 -0400 Subject: [PATCH 51/89] Update Parameter Counts --- Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 | 4 ++-- Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 index b8abfd8..aec697f 100644 --- a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 @@ -6,8 +6,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "$global:function should have exactly 16 parameters defined" { - (get-command $global:function).Parameters.Count | Should -Be 16 + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 } $ParameterTestCases = @( diff --git a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 index aec697f..b8abfd8 100644 --- a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 @@ -6,8 +6,8 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "$global:function should have exactly 15 parameters defined" { - (get-command $global:function).Parameters.Count | Should -Be 15 + it "$global:function should have exactly 16 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 16 } $ParameterTestCases = @( From fee7cd9723d11bf93f69900e9176e142eee7ad9d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 18:16:25 -0400 Subject: [PATCH 52/89] Add Parameter Validation Tests --- Tests/Public/Get-ZAAlert.Tests.ps1 | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAAlert.Tests.ps1 b/Tests/Public/Get-ZAAlert.Tests.ps1 index e6e6083..9695510 100644 --- a/Tests/Public/Get-ZAAlert.Tests.ps1 +++ b/Tests/Public/Get-ZAAlert.Tests.ps1 @@ -6,6 +6,47 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'limitTo'; Type = 'int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "LimitTo Parameter should have a Min value of 1" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1 + } + + It "LimitTo Parameter should have a Max value of 1000000" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 1000000 + } } Context "$global:function::Parameter Functional Tests" { From 8267474d8acdef51e6b211a0d59dbabc2d465ade Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 18:24:16 -0400 Subject: [PATCH 53/89] Update Mandatory Setting for DatastoreId --- ZertoApiWrapper/Public/Get-ZADatastore.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Public/Get-ZADatastore.ps1 b/ZertoApiWrapper/Public/Get-ZADatastore.ps1 index 60bdc9e..14f074a 100644 --- a/ZertoApiWrapper/Public/Get-ZADatastore.ps1 +++ b/ZertoApiWrapper/Public/Get-ZADatastore.ps1 @@ -20,7 +20,7 @@ function Get-ZADatastore { [Parameter( HelpMessage = "The datastore cluster identifier. Gets a list of datastores in the cluster.", ParameterSetName = "cluster", - Mandatory = "true" + Mandatory = $true )] [ValidateNotNullOrEmpty()] [string]$clusterIdentifier, From 21bc81b0eccb32102dcdaa456164ec9fbb7e293d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 18:24:34 -0400 Subject: [PATCH 54/89] Add Parameter Tests --- Tests/Public/Get-ZADatastore.Tests.ps1 | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZADatastore.Tests.ps1 b/Tests/Public/Get-ZADatastore.Tests.ps1 index e6e6083..c148811 100644 --- a/Tests/Public/Get-ZADatastore.Tests.ps1 +++ b/Tests/Public/Get-ZADatastore.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'datastoreIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'clusterIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From ba1e1c309e386d68681160e00b699b35a0164438 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 19:48:04 -0400 Subject: [PATCH 55/89] Add Parameter Tests --- Tests/Public/Get-ZAEvent.Tests.ps1 | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Tests/Public/Get-ZAEvent.Tests.ps1 b/Tests/Public/Get-ZAEvent.Tests.ps1 index e6e6083..e1e40f6 100644 --- a/Tests/Public/Get-ZAEvent.Tests.ps1 +++ b/Tests/Public/Get-ZAEvent.Tests.ps1 @@ -6,6 +6,66 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 16 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 16 + } + + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'limitTo'; Type = 'int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'category'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + 'Set' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "LimitTo Parameter should have a Min value of 1" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1 + } + + It "LimitTo Parameter should have a Max value of 1000000" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 1000000 + } + + It "Category parameter should only have 2 options" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should Be 2 + } + + It "Category parameter should take 'events'" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events' + } + + It "Category parameter should take 'alertsHistory'" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alertsHistory' + } } Context "$global:function::Parameter Functional Tests" { From c83462d03c7afea54bde819c596ee8ac631e0b6c Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:08:54 -0400 Subject: [PATCH 56/89] Add Parameter Tests --- .../Get-ZAJournalAverageHistory.Tests.ps1 | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 b/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 index e6e6083..80bf748 100644 --- a/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalAverageHistory.Tests.ps1 @@ -6,6 +6,48 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 878622d3e2f91338027af7be95a875a7232d21fa Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:20:31 -0400 Subject: [PATCH 57/89] Add Parameter Tests --- .../Public/Get-ZAJournalAverageSize.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 b/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 index e6e6083..f013489 100644 --- a/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalAverageSize.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 356572a1f8bfb367a11140b3a4477ea30a178c07 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:24:07 -0400 Subject: [PATCH 58/89] Add Parameter Tests --- Tests/Public/Get-ZAJournalBreach.Tests.ps1 | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZAJournalBreach.Tests.ps1 b/Tests/Public/Get-ZAJournalBreach.Tests.ps1 index e6e6083..b0761f1 100644 --- a/Tests/Public/Get-ZAJournalBreach.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalBreach.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 7fe361dba7c05caa3f4b7b08c640c999701874f6 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:26:24 -0400 Subject: [PATCH 59/89] Add Parameter Tests --- .../Public/Get-ZAJournalHistoryStat.Tests.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 b/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 index e6e6083..b0761f1 100644 --- a/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalHistoryStat.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From aaa505c7905cdcec4c4c75e487b72c2ecbee286a Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:30:22 -0400 Subject: [PATCH 60/89] Add Parameter Tests --- .../Get-ZAJournalSiteAverageHistory.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 index e6e6083..6583c27 100644 --- a/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteAverageHistory.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From fc3a2a0193eb1abd9f3e6b56fba6ede182c96773 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:31:53 -0400 Subject: [PATCH 61/89] Add Parameter Tests --- .../Get-ZAJournalSiteAverageSize.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 index e6e6083..6583c27 100644 --- a/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteAverageSize.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 6bc6f902fd4c706be83bdb77ab12ab9948886ae3 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:33:19 -0400 Subject: [PATCH 62/89] Add Parameter Tests --- .../Get-ZAJournalSiteHistoryStat.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 index e6e6083..6583c27 100644 --- a/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteHistoryStat.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From c578ec428ee08744884f8f8846e708930ffa91f1 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:35:26 -0400 Subject: [PATCH 63/89] Add Parameter Tests --- .../Get-ZAJournalSiteHistorySummary.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 index e6e6083..6583c27 100644 --- a/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteHistorySummary.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From c8da65120058355be03784330046f0a07f686333 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:37:32 -0400 Subject: [PATCH 64/89] Add Parameter Tests --- .../Get-ZAJournalSiteSizeStat.Tests.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 b/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 index e6e6083..6583c27 100644 --- a/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSiteSizeStat.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 15 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 79542e8f7ff7d992b2ff013754454ab6ae9f0c21 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:41:05 -0400 Subject: [PATCH 65/89] Add Parameter Tests --- .../Get-ZAJournalStatusProportion.Tests.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 b/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 index e6e6083..b0761f1 100644 --- a/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalStatusProportion.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 96803e1ad560927049df5563231652dcab1f75d1 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:42:12 -0400 Subject: [PATCH 66/89] Add Parameter Tests --- .../Public/Get-ZAJournalStorageStat.Tests.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 b/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 index e6e6083..b0761f1 100644 --- a/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalStorageStat.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 5e12656a4a865a2effdb0d76670e0c3cd8156b5b Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:44:35 -0400 Subject: [PATCH 67/89] Add Parameter Tests --- Tests/Public/Get-ZAJournalSummary.Tests.ps1 | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZAJournalSummary.Tests.ps1 b/Tests/Public/Get-ZAJournalSummary.Tests.ps1 index e6e6083..b0761f1 100644 --- a/Tests/Public/Get-ZAJournalSummary.Tests.ps1 +++ b/Tests/Public/Get-ZAJournalSummary.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 14 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From d2eddea4bc94e47072a7a8b27440cdcffe525e36 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:51:01 -0400 Subject: [PATCH 68/89] Add Parameter Tests --- Tests/Public/Get-ZALicense.Tests.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Get-ZALicense.Tests.ps1 b/Tests/Public/Get-ZALicense.Tests.ps1 index e6e6083..c7e8462 100644 --- a/Tests/Public/Get-ZALicense.Tests.ps1 +++ b/Tests/Public/Get-ZALicense.Tests.ps1 @@ -5,7 +5,9 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - + it "$global:function should have exactly 11 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 11 + } } Context "$global:function::Parameter Functional Tests" { From 6a924067c9278aadfd86a0cac4c1e77d3faf06ac Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 21 Jul 2019 20:57:25 -0400 Subject: [PATCH 69/89] Add Parameter Tests --- Tests/Public/Get-ZAMonitoring.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/Public/Get-ZAMonitoring.Tests.ps1 b/Tests/Public/Get-ZAMonitoring.Tests.ps1 index e6e6083..69c36ca 100644 --- a/Tests/Public/Get-ZAMonitoring.Tests.ps1 +++ b/Tests/Public/Get-ZAMonitoring.Tests.ps1 @@ -5,7 +5,14 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + it "$global:function should have exactly 12 parameters defined" { + (get-command $global:function).Parameters.Count | Should -Be 12 + } + it "$global:function has a non-mandatory string parameter for the zOrgIdentifier" { + Get-Command $global:function | Should -HaveParameter zOrgIdentifier -Type String + Get-Command $global:function | Should -HaveParameter zOrgIdentifier -not -Mandatory + } } Context "$global:function::Parameter Functional Tests" { From e07b99613e7a6f0b29e0d2410c5a5637aca5d6c3 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 17:08:17 -0400 Subject: [PATCH 70/89] Add Parameter Tests --- .../Get-ZANetworkSiteAverageIOPS.Tests.ps1 | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 index e6e6083..df1588a 100644 --- a/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteAverageIOPS.Tests.ps1 @@ -5,7 +5,50 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 17 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 17 + } + $ParameterTestCases = @( + @{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 1be09bd7345181c6cb55598622e8dfba73f443eb Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 19:52:54 -0400 Subject: [PATCH 71/89] Add Parameter Tests --- ...-ZANetworkSiteAveragePerformance.Tests.ps1 | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 index e6e6083..df1588a 100644 --- a/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteAveragePerformance.Tests.ps1 @@ -5,7 +5,50 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 17 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 17 + } + $ParameterTestCases = @( + @{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From b294f3e6ada66c08f07cc175a95e9e775f97a637 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 19:54:39 -0400 Subject: [PATCH 72/89] Add Parameter Tests --- Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 index e6e6083..80f948f 100644 --- a/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteStat.Tests.ps1 @@ -5,7 +5,41 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 16 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 16 + } + $ParameterTestCases = @( + @{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From b5a637fe603f1e7fb6af0f58018bdd3d94b7b595 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 19:59:02 -0400 Subject: [PATCH 73/89] Add Parameter Tests --- .../Public/Get-ZANetworkSiteSummary.Tests.ps1 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 b/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 index e6e6083..80f948f 100644 --- a/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkSiteSummary.Tests.ps1 @@ -5,7 +5,41 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 16 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 16 + } + $ParameterTestCases = @( + @{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From e7512020103cd1c8eddc56320d8573433cf6ae4e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 20:03:52 -0400 Subject: [PATCH 74/89] Add Parameter Tests --- .../Get-ZANetworkVpgAverageIOPS.Tests.ps1 | 41 +++++++++++++++++++ ...t-ZANetworkVpgAveragePerformance.Tests.ps1 | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 index e6e6083..191f7a9 100644 --- a/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgAverageIOPS.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 15 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 index e6e6083..191f7a9 100644 --- a/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgAveragePerformance.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 15 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From 28fabd592c058f4cfe6f2fe9aa27140f71ece754 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 20:09:03 -0400 Subject: [PATCH 75/89] Add Parameter Tests --- Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 | 32 +++++++++++++++++++ .../Public/Get-ZANetworkVpgSummary.Tests.ps1 | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 index e6e6083..e9026db 100644 --- a/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgStat.Tests.ps1 @@ -5,7 +5,39 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 b/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 index e6e6083..e9026db 100644 --- a/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 +++ b/Tests/Public/Get-ZANetworkVpgSummary.Tests.ps1 @@ -5,7 +5,39 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From ad6b154d851393d82e8d4b39a2ebe29fe2f883d7 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 20:52:34 -0400 Subject: [PATCH 76/89] Add Parameter Tests --- .../Public/Get-ZARPOAccountAverage.Tests.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 b/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 index e6e6083..18f58ae 100644 --- a/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 +++ b/Tests/Public/Get-ZARPOAccountAverage.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 1d6c2289e831a29460ce2b30ed7f11283b20bd32 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 21:20:45 -0400 Subject: [PATCH 77/89] Add Parameter Tests --- Tests/Public/Get-ZARPOAverage.Tests.ps1 | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Public/Get-ZARPOAverage.Tests.ps1 b/Tests/Public/Get-ZARPOAverage.Tests.ps1 index e6e6083..8619700 100644 --- a/Tests/Public/Get-ZARPOAverage.Tests.ps1 +++ b/Tests/Public/Get-ZARPOAverage.Tests.ps1 @@ -5,7 +5,48 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 15 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 15 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'Interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 60" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 60 + } + + It "Interval Parameter should have a Max value of 2678400" { + (Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 2678400 + } } Context "$global:function::Parameter Functional Tests" { From c6b37c24a61b2f7d996cb5667768f1500a16d3b8 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 21:22:24 -0400 Subject: [PATCH 78/89] Add Parameter Tests --- Tests/Public/Get-ZARPOBreach.Tests.ps1 | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Public/Get-ZARPOBreach.Tests.ps1 b/Tests/Public/Get-ZARPOBreach.Tests.ps1 index e6e6083..38456f9 100644 --- a/Tests/Public/Get-ZARPOBreach.Tests.ps1 +++ b/Tests/Public/Get-ZARPOBreach.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 51a1e0fb033953ee27b98fe1f9f45232b0e49a96 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 21:27:14 -0400 Subject: [PATCH 79/89] Add Parameter Tests --- Tests/Public/Get-ZARPOStat.Tests.ps1 | 27 +++++++++++++++++++ .../Get-ZARPOStatusProportion.Tests.ps1 | 27 +++++++++++++++++++ Tests/Public/Get-ZARPOSummary.Tests.ps1 | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/Tests/Public/Get-ZARPOStat.Tests.ps1 b/Tests/Public/Get-ZARPOStat.Tests.ps1 index e6e6083..38456f9 100644 --- a/Tests/Public/Get-ZARPOStat.Tests.ps1 +++ b/Tests/Public/Get-ZARPOStat.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 b/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 index e6e6083..38456f9 100644 --- a/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 +++ b/Tests/Public/Get-ZARPOStatusProportion.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZARPOSummary.Tests.ps1 b/Tests/Public/Get-ZARPOSummary.Tests.ps1 index e6e6083..38456f9 100644 --- a/Tests/Public/Get-ZARPOSummary.Tests.ps1 +++ b/Tests/Public/Get-ZARPOSummary.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From c96836c0008a9520df2987bc6377e00210de9c09 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 21:46:31 -0400 Subject: [PATCH 80/89] Add Parameter Tests --- Tests/Public/Get-ZASite.Tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/Public/Get-ZASite.Tests.ps1 b/Tests/Public/Get-ZASite.Tests.ps1 index e6e6083..fd61b07 100644 --- a/Tests/Public/Get-ZASite.Tests.ps1 +++ b/Tests/Public/Get-ZASite.Tests.ps1 @@ -5,6 +5,17 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 12 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 12 + } + + It "zOrgIdentifier Parameter should be present and of 'String' Type" { + Get-Command $global:function | Should -HaveParameter zOrgIdentifier -Type String -Mandatory:$false + } + + It "zOrgIdentifier has the NotNullOrEmpty Validator" { + (Get-Command $global:function).Parameters['zOrgIdentifier'].Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should Be 1 + } } From baf6aa50eec7ac131f217904fee5815e736f3af1 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 22 Jul 2019 21:55:28 -0400 Subject: [PATCH 81/89] Add Parameter Tests --- Tests/Public/Get-ZASitePair.Tests.ps1 | 27 +++++++++++++++++++++++ Tests/Public/Get-ZASiteTopology.Tests.ps1 | 25 +++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Tests/Public/Get-ZASitePair.Tests.ps1 b/Tests/Public/Get-ZASitePair.Tests.ps1 index e6e6083..18f58ae 100644 --- a/Tests/Public/Get-ZASitePair.Tests.ps1 +++ b/Tests/Public/Get-ZASitePair.Tests.ps1 @@ -5,7 +5,34 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZASiteTopology.Tests.ps1 b/Tests/Public/Get-ZASiteTopology.Tests.ps1 index e6e6083..f1136ba 100644 --- a/Tests/Public/Get-ZASiteTopology.Tests.ps1 +++ b/Tests/Public/Get-ZASiteTopology.Tests.ps1 @@ -5,7 +5,32 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 12 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 12 + } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 27694899390daecac9605cea7b30e708210d8c73 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:27:11 -0400 Subject: [PATCH 82/89] Create Parameter Tests --- Tests/Public/Get-ZATask.Tests.ps1 | 40 +++++++++++++++++++++++++++++ Tests/Public/Get-ZAVolume.Tests.ps1 | 32 +++++++++++++++++++++-- Tests/Public/Get-ZAVpg.Tests.ps1 | 30 ++++++++++++++++++++-- Tests/Public/Get-ZAzOrg.Tests.ps1 | 4 ++- 4 files changed, 101 insertions(+), 5 deletions(-) diff --git a/Tests/Public/Get-ZATask.Tests.ps1 b/Tests/Public/Get-ZATask.Tests.ps1 index e6e6083..7e712d4 100644 --- a/Tests/Public/Get-ZATask.Tests.ps1 +++ b/Tests/Public/Get-ZATask.Tests.ps1 @@ -5,7 +5,47 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 14 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 14 + } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'limitTo'; Type = 'Int'; Mandatory = $false; Validation = 'Range' } + @{ParameterName = 'taskIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Range' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "Interval Parameter should have a Min value of 1" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1 + } + + It "Interval Parameter should have a Max value of 1000000" { + (Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 1000000 + } } Context "$global:function::Parameter Functional Tests" { diff --git a/Tests/Public/Get-ZAVolume.Tests.ps1 b/Tests/Public/Get-ZAVolume.Tests.ps1 index e6e6083..c4b6a8c 100644 --- a/Tests/Public/Get-ZAVolume.Tests.ps1 +++ b/Tests/Public/Get-ZAVolume.Tests.ps1 @@ -5,11 +5,39 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 15 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 15 + } - } + $ParameterTestCases = @( + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'clusterIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'datastoreIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) - Context "$global:function::Parameter Functional Tests" { + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + Context "$global:function::Parameter Functional Tests" { + + } } } diff --git a/Tests/Public/Get-ZAVpg.Tests.ps1 b/Tests/Public/Get-ZAVpg.Tests.ps1 index e6e6083..ae44aa0 100644 --- a/Tests/Public/Get-ZAVpg.Tests.ps1 +++ b/Tests/Public/Get-ZAVpg.Tests.ps1 @@ -5,11 +5,37 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 13 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 13 + } - } + $ParameterTestCases = @( + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + ) - Context "$global:function::Parameter Functional Tests" { + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + Context "$global:function::Parameter Functional Tests" { + + } } } diff --git a/Tests/Public/Get-ZAzOrg.Tests.ps1 b/Tests/Public/Get-ZAzOrg.Tests.ps1 index e6e6083..8ac00f2 100644 --- a/Tests/Public/Get-ZAzOrg.Tests.ps1 +++ b/Tests/Public/Get-ZAzOrg.Tests.ps1 @@ -5,7 +5,9 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - + It "$global:function should have exactly 11 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 11 + } } Context "$global:function::Parameter Functional Tests" { From 4e7d30ef332bf8c8605234c74f53a839e7cdbe8e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:30:30 -0400 Subject: [PATCH 83/89] Add NullOrEmpty validation test --- Tests/Public/Get-ZertoDatastore.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Public/Get-ZertoDatastore.Tests.ps1 b/Tests/Public/Get-ZertoDatastore.Tests.ps1 index 6727a99..5deb346 100644 --- a/Tests/Public/Get-ZertoDatastore.Tests.ps1 +++ b/Tests/Public/Get-ZertoDatastore.Tests.ps1 @@ -10,6 +10,10 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Get-Command $global:function | Should -HaveParameter datastoreIdentifier Get-Command $global:function | Should -HaveParameter datastoreIdentifier -Type String[] } + + It "datastoreIdentifier parameter does not take null or empty values" { + (Get-Command $global:function).Parameters['datastoreIdentifier'].Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.count | Should Be 1 + } } Context "$global:function::Parameter Functional Tests" { From fd1619351edc8eca8b8dc3faa9ea6257ddca952e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:51:13 -0400 Subject: [PATCH 84/89] Update Parameter Tests --- Tests/Public/Get-ZertoEvent.Tests.ps1 | 103 ++++++++++++++++++++++ ZertoApiWrapper/Public/Get-ZertoEvent.ps1 | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Get-ZertoEvent.Tests.ps1 b/Tests/Public/Get-ZertoEvent.Tests.ps1 index e6e6083..b257e26 100644 --- a/Tests/Public/Get-ZertoEvent.Tests.ps1 +++ b/Tests/Public/Get-ZertoEvent.Tests.ps1 @@ -5,7 +5,110 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 28 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 28 + } + $ParameterTestCases = @( + @{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpg'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'eventType'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'entityType'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'userName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'category'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'eventCategory'; Type = 'String'; Mandatory = $false; Validation = 'Set' } + @{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'eventId'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'categories'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'entities'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'types'; Type = 'Switch'; Mandatory = $true; Validation = $null } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + 'Set' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1 + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } + + It "entityType parameter only accecpts 4 different values" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 4 + } + + It "entityType parameter accecpts 'VPG' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VPG' + } + + It "entityType parameter accecpts 'VRA' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VRA' + } + + It "entityType parameter accecpts 'Unknown' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Unknown' + } + + It "entityType parameter accecpts 'Site' as a Value" { + (Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Site' + } + + It "category parameter only accecpts 3 different values" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 3 + } + + It "category parameter accecpts 'All' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All' + } + + It "category parameter accecpts 'events' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events' + } + + It "category parameter accecpts 'alerts' as a Value" { + (Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts' + } + + It "eventCategory parameter only accecpts 3 different values" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should be 3 + } + + It "eventCategory parameter accecpts 'All' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All' + } + + It "eventCategory parameter accecpts 'events' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events' + } + + It "eventCategory parameter accecpts 'alerts' as a Value" { + (Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts' + } } Context "$global:function::Parameter Functional Tests" { diff --git a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 index 1c45ee8..76584f6 100644 --- a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 @@ -69,7 +69,7 @@ function Get-ZertoEvent { ParameterSetName = "filter", HelpMessage = "The type of event to return. This filter behaves in the same way as the eventCategory filter. Possible Values are: Possible Values are: 'All', 'Events', 'Alerts'" )] - [ValidateNotNullOrEmpty()] + [ValidateSet('All','Events','Alerts')] [string]$category, [Parameter( ParameterSetName = "filter", From 73884ef022c546af93ba5e3f5f084346c2c650c8 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:57:01 -0400 Subject: [PATCH 85/89] Update Parameter Tests --- Tests/Public/Get-ZertoLicense.Tests.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Get-ZertoLicense.Tests.ps1 b/Tests/Public/Get-ZertoLicense.Tests.ps1 index e6e6083..8ac00f2 100644 --- a/Tests/Public/Get-ZertoLicense.Tests.ps1 +++ b/Tests/Public/Get-ZertoLicense.Tests.ps1 @@ -5,7 +5,9 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - + It "$global:function should have exactly 11 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 11 + } } Context "$global:function::Parameter Functional Tests" { From 8b0def7c50f8020f395e64cd815bf1741a9f17d2 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 12:59:23 -0400 Subject: [PATCH 86/89] Update Parameter Tests --- Tests/Public/Get-ZertoLocalSite.Tests.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 index 4fea226..fe3af42 100644 --- a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 @@ -5,7 +5,11 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { - it "Has a non-mandatory switch parameter for the pairing Statuses" { + It "$global:function should have exactly 12 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 12 + } + + It "Has a non-mandatory switch parameter for the pairing Statuses" { Get-Command $global:function | Should -HaveParameter pairingstatuses Get-Command $global:function | Should -HaveParameter pairingstatuses -Type switch } From 5c2e16d5c6224270dd35fbca7fe1799f130661a4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 13:13:24 -0400 Subject: [PATCH 87/89] Add Parameter Validation --- ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 b/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 index 8f64673..cb86c53 100644 --- a/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 @@ -22,6 +22,7 @@ function Get-ZertoPeerSite { ParameterSetName = "filter", HelpMessage = "The name of a peer site for which information is to be returned. The name is case-sensitive." )] + [ValidateNotNullOrEmpty()] [string]$peerName, [Parameter ( ParameterSetName = "filter", From 916fbb6c4c90040c67feeb2e97d2b949963a4171 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 23 Jul 2019 13:13:38 -0400 Subject: [PATCH 88/89] Add Parameter Validation Tests --- Tests/Public/Get-ZertoPeerSite.Tests.ps1 | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 index e6e6083..2583c97 100644 --- a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 @@ -5,7 +5,43 @@ $global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$global:function::Parameter Unit Tests" { + It "$global:function should have exactly 18 parameters defined" { + (Get-Command $global:function).Parameters.Count | Should -Be 18 + } + $ParameterTestCases = @( + @{ParameterName = 'pairingStatuses'; Type = 'Switch'; Mandatory = $true; Validation = $null } + @{ParameterName = 'siteIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'peerName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'paringStatus'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'location'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'hostName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'port'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } + ) + + It " parameter is of type" -TestCases $ParameterTestCases { + param($ParameterName, $Type, $Mandatory, $Validation) + Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type + } + + It " parameter has correct validation setting" -TestCases $ParameterTestCases { + param($ParameterName, $Validation) + Switch ($Validation) { + 'NotNullOrEmpty' { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1 + } + + $null { + $attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes + $attrs.TypeId.Count | Should -Be 2 + } + + default { + $true | Should be $false -Because "No Validation Selected. Review test cases" + } + } + } } Context "$global:function::Parameter Functional Tests" { From 551eac5d5a966bcae8b95f61781f5ceafb4bb6be Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 26 Jul 2019 11:06:07 -0400 Subject: [PATCH 89/89] Update release notes for testing changes --- .gitignore | 1 + RELEASENOTES.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index be77f6b..ee2dd02 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ BuiltTestResults.xml SourceTestResults.xml publish/* CodeCoverage.xml +scratch diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 33751db..4a6b468 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -10,3 +10,7 @@ * Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/36) where the Zerto Analytics Rest Request function was not checking for the token before attempting a connection. * Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/40) where the `Get-ZAVpg` method would return a 404 error when a `-vpgIdentifier` parameter was specified. + +### General Updates + +* Updated the way that tests are invoked and parsed to ensure that both source and built module files are tested. This will ensure that what is being shipped passes all tests along with testing of the source files.