From 562d1210e6665a539c0f4d641875f688d4dcf1b4 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 15:31:44 -0400 Subject: [PATCH] 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 }