From bc2cee118ca035eec881fa25c5085c2898245165 Mon Sep 17 00:00:00 2001 From: Alden Hilton Date: Mon, 30 Sep 2024 13:22:14 -0700 Subject: [PATCH] Correctly mock the Get-Uft8NoBom function --- .../PowerShell/Orchestrator/Invoke-ReportCreation.Tests.ps1 | 4 ++-- .../PowerShell/Orchestrator/Invoke-ScubaCached.Tests.ps1 | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ReportCreation.Tests.ps1 b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ReportCreation.Tests.ps1 index 630c88f3b..22c1f7a6e 100644 --- a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ReportCreation.Tests.ps1 +++ b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ReportCreation.Tests.ps1 @@ -1,9 +1,8 @@ $OrchestratorPath = '../../../../Modules/Orchestrator.psm1' $CreateReportPath = '../../../../Modules/CreateReport/CreateReport.psm1' -$UtilityPath = '../../../../Modules/Utility/Utility.psm1' Import-Module (Join-Path -Path $PSScriptRoot -ChildPath $OrchestratorPath) -Function Invoke-ReportCreation -Force Import-Module (Join-Path -Path $PSScriptRoot -ChildPath $CreateReportPath) -Function New-Report, Import-SecureBaseline -Force -Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath $UtilityPath) -Function Get-Utf8NoBom -Force + InModuleScope Orchestrator { Describe -Tag 'Orchestrator' -Name 'Invoke-ReportCreation' { BeforeAll { @@ -20,6 +19,7 @@ InModuleScope Orchestrator { Mock -CommandName Get-Content {} Mock -CommandName Add-Type {} Mock -CommandName Invoke-Item {} + function Get-Utf8NoBom {throw 'this will be mocked'} Mock -CommandName Get-Utf8NoBom {} Mock -CommandName ConvertFrom-Json { @{ "report_uuid"="" } } } diff --git a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ScubaCached.Tests.ps1 b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ScubaCached.Tests.ps1 index cdb6d2dcd..1dfdb395a 100644 --- a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ScubaCached.Tests.ps1 +++ b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/Invoke-ScubaCached.Tests.ps1 @@ -119,15 +119,15 @@ InModuleScope Orchestrator { {Invoke-SCuBACached @SplatParams} | Should -Not -Throw } It 'Given an existing UUID should not generate a new one' { - # Get-Member was mocked above to return True so the as far as the + # Get-Member was mocked above to return True so as far as the # provider can tell, the existing output already has a UUID {Invoke-SCuBACached @SplatParams} | Should -Not -Throw Should -Invoke -CommandName New-Guid -Exactly -Times 0 } It 'Given output without a UUID should generate a new one' { Mock -CommandName Get-Member { $false } - # Now Get-Member will return False so the as far as the - # provider can tell, the existing output does not have a UUID + # Now Get-Member will return False so as far as the provider + # can tell, the existing output does not have a UUID {Invoke-SCuBACached @SplatParams} | Should -Not -Throw Should -Invoke -CommandName New-Guid -Exactly -Times 1 }