functions/general/Beautify-TmfTestResult.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function Beautify-TmfTestResult
{
    <#
        .SYNOPSIS
            Beautifies the returned output of the Test-TmfRESOURCE functions.

        .PARAMETER TestResult
            The input test result object.

        .PARAMETER FunctionName
            Name of the function which returned the output.

        .PARAMETER DoNotShowPropertyChanges
            Do not print property changes from the test result object.

        .EXAMPLE
            PS> Test-TmfGroup | Beautify-TmfTestResult
    #>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [object] $TestResult,
        [string] $FunctionName = "TMF",
        [switch] $DoNotShowPropertyChanges
    )
    
    process
    {
        Write-PSFMessage -Level Host -FunctionName $FunctionName -String "TMF.TestResult.BeautifySimple" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $TestResult.ActionType, (Get-ActionColor -Action $TestResult.ActionType)
        if (!$DoNotShowPropertyChanges) {
            if ($TestResult.ActionType -eq "Update") {
                foreach ($change in $TestResult.Changes) {
                    foreach ($action in $change.Actions.Keys) {                        
                        $value = $change.Actions[$action] | ConvertTo-Json -Compress -Depth 8
                        Write-PSFMessage -Level Host -FunctionName $FunctionName -String "TMF.TestResult.BeautifyPropertyChange" -StringValues $TestResult.Tenant, $TestResult.ResourceName, $TestResult.ResourceType, $change.Property, $action, $value
                    }
                }
            }
        }
    }
}