. $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 = "" Describe "Get-HelmApplicationYamls" { Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { "SUT" } Mock -ModuleName $moduleForMock -CommandName Get-Content -MockWith {} Mock -ModuleName $moduleForMock -CommandName ConvertFrom-Yaml -MockWith {} # Don't reimplement core module functionality, everything should be driven from inputs # Mock -ModuleName $moduleForMock -CommandName Join-Path -MockWith {} Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { $true } Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {} Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {} Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {} Context "It does not error on the happy path" { It "Does not throw" { { Get-HelmApplicationYamls -RepoPath "TestDrive:\" -EnvironmentName "pester" } | Should Not Throw } It "Does not return an empty item" { Get-HelmApplicationYamls -RepoPath "TestDrive:\" -EnvironmentName "pester" | Should Not BeNullOrEmpty } } # Tests as documentation, these are the expected throwing conditions for sure Context "Getting bad file data throws as expected" { It "Throws for no content" { Mock -ModuleName $moduleForMock -CommandName ConvertFrom-Yaml -MockWith { throw "No content was processed"} { Get-HelmApplicationYamls -RepoPath "TestDrive:\" -EnvironmentName "pester" } | Should Throw } It "Throws for not being able to find the file" { Mock -ModuleName $moduleForMock -CommandName Get-Content -MockWith { throw "Can't find the file" } { Get-HelmApplicationYamls -RepoPath "TestDrive:\" -EnvironmentName "pester" } | Should Throw } } }