add pester tests for Resolve-Dependency
This commit is contained in:
parent
b325fea2bb
commit
0dae01d141
@ -53,11 +53,12 @@ function Resolve-Dependency {
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Name
|
[string]$Name
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
$ModuleRootDir = $MyInvocation.MyCommand.Module.ModuleBase
|
$ModuleRootDir = Get-ModuleBase
|
||||||
$DepFilePath = Join-Path -Path $ModuleRootDir -ChildPath "Dependency.json"
|
$DepFilePath = Join-Path -Path $ModuleRootDir -ChildPath "Dependency.json"
|
||||||
if (Test-Path -Path $DepFilePath) {
|
if (Test-Path -Path $DepFilePath) {
|
||||||
$Dependency = Get-Content -Path $DepFilePath -Raw -Encoding UTF8 | ConvertFrom-Json
|
$Dependency = Get-Content -Path $DepFilePath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
31
tests/Helper/01_Resolve-Dependendy.Tests.ps1
Normal file
31
tests/Helper/01_Resolve-Dependendy.Tests.ps1
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#region HEADER
|
||||||
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName
|
||||||
|
$RepoRoot = (Get-GitDirectory).replace('\.git', '')
|
||||||
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
|
||||||
|
$sut = $sut -replace "\d{2}`_", ''
|
||||||
|
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName
|
||||||
|
# Skip try loading the source file if it doesn't exists.
|
||||||
|
If ($suthome.Length -gt 0) {
|
||||||
|
. $suthome
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
Write-Warning ("Could not find source file {0}" -f $sut)
|
||||||
|
}
|
||||||
|
|
||||||
|
# load additional functions defined in the repository. Replace the expression <FunctionName>.
|
||||||
|
#. (Get-ChildItem -Path $RepoRoot -Filter "<FunctionName>.ps1" -Recurse).FullName
|
||||||
|
#endregion HEADER
|
||||||
|
|
||||||
|
Describe "Resolve-Dependency" {
|
||||||
|
Context "Basic syntax check" {
|
||||||
|
Mock Get-ModuleBase {return "{0}\resources" -f $PWD}
|
||||||
|
Mock Test-Module {return $true}
|
||||||
|
It "Test1: Should not throw" {
|
||||||
|
{ Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw
|
||||||
|
}
|
||||||
|
It "Test2: Output type should be bool" {
|
||||||
|
Resolve-Dependency -Name 'foobar2000' | Should -BeOfType system.bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user