ps/Modules/Alkami.PowerShell.Common/Public/Test-IsPsModuleInstalled.tests.ps1

34 lines
991 B
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
#region Test-IsPsModuleInstalled
Describe "Test-IsPsModuleInstalled" {
Context "When Module Exists" {
It "Returns True" {
Mock -ModuleName $moduleForMock Get-Module -MockWith {
return [PSCustomObject]@{ModuleType = "I am a fake module" }
}
Test-IsPsModuleInstalled FakeModule | Should Be $true
}
}
Context "When Module Does Not Exist" {
It "Returns False" {
Mock -ModuleName $moduleForMock Get-Module { return $null }
Test-IsPsModuleInstalled NonExistentModule | Should Be $false
}
}
}
#endregion Test-IsPsModuleInstalled