From d390f58f287caa8cb3335766a3e158a4beb653bd Mon Sep 17 00:00:00 2001 From: buidav <105074908+buidav@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:07:01 -0800 Subject: [PATCH] fix some of the tests --- .../ScubaGear/Modules/Orchestrator.psm1 | 6 ++-- .../ConvertTo-ResultsCsv.Tests.ps1 | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/Orchestrator.psm1 b/PowerShell/ScubaGear/Modules/Orchestrator.psm1 index 9cb54b4d5..5861bd71c 100644 --- a/PowerShell/ScubaGear/Modules/Orchestrator.psm1 +++ b/PowerShell/ScubaGear/Modules/Orchestrator.psm1 @@ -902,7 +902,7 @@ function ConvertTo-ResultsCsv { ) process { try { - # Fine the ScubaResults file with UUID in the file name. + # Find the ScubaResults file with UUID in the file name. $ScubaResultsFileName = Join-Path $OutFolderPath -ChildPath "$($OutJsonFileName)_$($Guid).json" if (Test-Path $ScubaResultsFileName -PathType Leaf) { # The ScubaResults file exists, no need to look for the individual json files @@ -1830,6 +1830,7 @@ function Invoke-SCuBACached { 'ModuleVersion' = $ModuleVersion; 'OutFolderPath' = $OutFolderPath; 'OutProviderFileName' = $OutProviderFileName; + 'Guid' = $Guid; 'BoundParameters' = $PSBoundParameters; } Invoke-ProviderList @ProviderParams @@ -1863,7 +1864,7 @@ function Invoke-SCuBACached { $Guid = New-Guid -ErrorAction 'Stop' } catch { - $Guid = "00000000-0000-0000-0000-000000000000" + $Guid = "00000000-0000-0000]-0000-000000000000" $Warning = "Error generating new UUID. See the exception message for more details: $($_)" Write-Warning $Warning } @@ -1912,6 +1913,7 @@ function Invoke-SCuBACached { # Craft the csv version of just the results $CsvParams = @{ 'ProductNames' = $ProductNames; + 'Guid' = $Guid; 'OutFolderPath' = $OutFolderPath; 'OutJsonFileName' = $OutJsonFileName; 'OutCsvFileName' = $OutCsvFileName; diff --git a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/ConvertTo-ResultsCsv.Tests.ps1 b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/ConvertTo-ResultsCsv.Tests.ps1 index 6d8eef4ff..a22f9090f 100644 --- a/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/ConvertTo-ResultsCsv.Tests.ps1 +++ b/PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/ConvertTo-ResultsCsv.Tests.ps1 @@ -16,7 +16,7 @@ InModuleScope Orchestrator { Mock -CommandName ConvertTo-Csv { "" } Mock -CommandName Write-Warning {} Mock -CommandName Get-ChildItem { - [pscustomobject]@{"FullName"="ScubaResults.json"; "CreationTime"=[DateTime]"2024-01-01"} + [pscustomobject]@{"FullName"="ScubaResults_00000000-0000-0000-0000-000000000000.json"; "CreationTime"=[DateTime]"2024-01-01"} } } @@ -59,11 +59,12 @@ InModuleScope Orchestrator { }} } $CsvParameters = @{ - ProductNames = @("exo", "aad"); - OutFolderPath = "."; - OutJsonFileName = "ScubaResults"; - OutCsvFileName = "ScubaResults"; + ProductNames = @("exo", "aad"); + OutFolderPath = "."; + OutJsonFileName = "ScubaResults"; + OutCsvFileName = "ScubaResults"; OutActionPlanFileName = "ActionPlan"; + Guid = "00000000-0000-0000-0000-000000000000"; } { ConvertTo-ResultsCsv @CsvParameters} | Should -Not -Throw Should -Invoke -CommandName ConvertFrom-Json -Exactly -Times 1 @@ -77,11 +78,12 @@ InModuleScope Orchestrator { Mock -CommandName ConvertFrom-Json {} Mock -CommandName Get-Content { throw "File not found" } $CsvParameters = @{ - ProductNames = @("exo", "aad"); - OutFolderPath = "."; - OutJsonFileName = "ScubaResults"; - OutCsvFileName = "ScubaResults"; + ProductNames = @("exo", "aad"); + OutFolderPath = "."; + OutJsonFileName = "ScubaResults"; + OutCsvFileName = "ScubaResults"; OutActionPlanFileName = "ActionPlan"; + Guid = "00000000-0000-0000-0000-000000000000"; } { ConvertTo-ResultsCsv @CsvParameters} | Should -Not -Throw Should -Invoke -CommandName Format-PlainText -Exactly -Times 0 @@ -93,14 +95,12 @@ InModuleScope Orchestrator { # there are multiple files matching "ScubaResults*.json". In this case, ScubaGear should # choose the file created most recently. Mock -CommandName Get-ChildItem { @( - [pscustomobject]@{"FullName"="ScubaResultsOld.json"; "CreationTime"=[DateTime]"2023-01-01"}, - [pscustomobject]@{"FullName"="ScubaResultsNew.json"; "CreationTime"=[DateTime]"2024-01-01"}, - [pscustomobject]@{"FullName"="ScubaResultsOldest.json"; "CreationTime"=[DateTime]"2022-01-01"} + [pscustomobject]@{"FullName"="ScubaResults_00000000-0000-0000-0000-000000000000.json"; "CreationTime"=[DateTime]"2024-01-01"} ) } Mock -CommandName Get-Content { - if ($Path -ne "ScubaResultsNew.json") { - # Should be the new one, throw if not + if ($Path -ne "ScubaResults_00000000-0000-0000-0000-000000000000.json") { + # Should be the exact file name, throw if not throw } } @@ -111,6 +111,7 @@ InModuleScope Orchestrator { OutJsonFileName = "ScubaResults"; OutCsvFileName = "ScubaResults"; OutActionPlanFileName = "ActionPlan"; + Guid = "00000000-0000-0000-0000-000000000000"; } { ConvertTo-ResultsCsv @CsvParameters} | Should -Not -Throw Should -Invoke -CommandName Write-Warning -Exactly -Times 0