Update Tests for Mutlirun

This commit is contained in:
Wes Carroll
2019-07-15 15:31:44 -04:00
parent d7ee3eab12
commit 562d1210e6
+65 -24
View File
@@ -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
}