Update tests to new format

This commit is contained in:
Wes Carroll
2019-07-20 20:14:58 -04:00
parent ff54a92f92
commit c05a527982
+13 -26
View File
@@ -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