-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #773 from luis-gasparschroeder/json-format-piping
Implemented functionality to convert the test result format into JSON
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Function Format-Json { | ||
<# | ||
.SYNOPSIS | ||
Takes results from ARMTTK and exports them as a JSON blob. | ||
.DESCRIPTION | ||
Takes results from ARMTTK and exports them as JSON. The test cases include the filename, name of the test, | ||
whether the test was successful, and help text for how to resolve the error if the test failed. | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
# Object containing a single test result or an array of test results | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[psobject]$TestResult | ||
) | ||
|
||
Begin { | ||
# Initialize the array to collect processed test cases | ||
$TestCases = @() | ||
} | ||
|
||
Process { | ||
# Process each TestResult item one by one as they come from the pipeline | ||
$TestCase = @{ | ||
filepath = $TestResult.file.fullpath | ||
name = $TestResult.name | ||
success = $TestResult.Passed | ||
} | ||
|
||
if ($TestResult.Passed) { | ||
$TestCase.optional = $false | ||
} | ||
elseif ($null -ne $($TestResult.Warnings)) { | ||
$TestCase.optional = $true | ||
$TestCase.message = "$($TestResult.Warnings.Message.Replace('"', '\"')) in template file $($TestResult.file.name)" | ||
} | ||
elseif ($null -ne $($TestResult.Errors)) { | ||
$TestCase.optional = $false | ||
$TestCase.message = "$($TestResult.Errors.Exception.Message.Replace('"', '\"')) in template file $($TestResult.file.name)" | ||
} | ||
else { | ||
$TestCase.optional = $true | ||
$TestCase.message = "Unknown error in template file " + $TestResult.file.name | ||
} | ||
|
||
$TestCases += $TestCase | ||
} | ||
|
||
End { | ||
# Convert the array of hashtables to JSON | ||
$JSON = $TestCases | ConvertTo-Json | ||
|
||
# Print the JSON string to the console | ||
Write-Output $JSON | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters