Skip to content

Commit

Permalink
fix some of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buidav committed Nov 16, 2024
1 parent ebd7106 commit d390f58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
6 changes: 4 additions & 2 deletions PowerShell/ScubaGear/Modules/Orchestrator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1830,6 +1830,7 @@ function Invoke-SCuBACached {
'ModuleVersion' = $ModuleVersion;
'OutFolderPath' = $OutFolderPath;
'OutProviderFileName' = $OutProviderFileName;
'Guid' = $Guid;
'BoundParameters' = $PSBoundParameters;
}
Invoke-ProviderList @ProviderParams
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
Expand Down

0 comments on commit d390f58

Please sign in to comment.