Skip to content

[Test-ObjectGraph] Cmdlet does not include individual objects when the ListNode has two or more failing objects #127

@ykuijs

Description

@ykuijs

When the schema specifies a ListNode and the data contains just one failing object, the output lists that failing object:

Code:

$data = @{
    NonNodeData = @{
        AzureAD = @{
            AuthenticationMethodPolicy = @(
                @{
                    IncorrectProperty1 = 8
                    IncorrectProperty2 = 10
                }
                @{
                    DefaultLength = 8
                    DefaultLifetimeInMinutes = 10
                }
            )
        }
    }
}

$schema = @{
    NonNodeData = @{
        '@Type' = 'PSMapNode'
        AzureAD = @{
            '@Type' = 'PSMapNode'
            AuthenticationMethodPolicy = @(
                @{
                    '@Type' = 'PSMapNode'
                    DefaultLength = @{ '@Type' = 'Int' }
                    DefaultLifetimeInMinutes = @{ '@Type' = 'Int' }
                    Ensure = @{ '@Type' = 'String' }
                    Id = @{ '@Type' = 'String' }
                    IncludeTargets = @(
                        @{
                            '@Type' = 'PSMapNode'
                            Id = @{ '@Type' = 'String' }
                            TargetType = @{ '@Type' = 'String' }
                        }
                    )
                    IsUsableOnce = @{ '@Type' = 'Bool' }
                    MaximumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    MinimumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    State = @{ '@Type' = 'String' }
                }
            )
        }
    }
}

$result = $data | Test-Object $schema
$result

Output:

Path                                              Value                                      Valid Issue
----                                              -----                                      ----- -----
NonNodeData.AzureAD.AuthenticationMethodPolicy[0] @{IncorrectPr…=10;IncorrectPr…=8}           [X]  The following nodes are not accepted: IncorrectPr…, IncorrectPr…
NonNodeData.AzureAD.AuthenticationMethodPolicy    @(@{IncorrectPr…=…;…},@{DefaultLeng…=…;…})  [X]  The following nodes are not accepted: 0
NonNodeData.AzureAD                               @{Authenticat…=@(…)}                        [X]  The following nodes are not accepted: Authenticat…
NonNodeData                                       @{AzureAD=@{Authenticat…=…}}                [X]  The following nodes are not accepted: AzureAD
                                                  @{NonNodeData=@{AzureAD=…}}                 [X]  The following nodes are not accepted: NonNodeData

The first line in the output specifies the NonNodeData.AzureAD.AuthenticationMethodPolicy[0] object which is failing, with the failing parameters in the Issue column.

When specifying two objects that are failing, the code suddenly ignores the individual objects in the output:

Code:

$data = @{
    NonNodeData = @{
        AzureAD = @{
            AuthenticationMethodPolicy = @(
                @{
                    IncorrectProperty1 = 8
                    IncorrectProperty2 = 10
                }
                @{
                    IncorrectProperty1 = 16
                    IncorrectProperty2 = 20
                }
            )
        }
    }
}

$schema = @{
    NonNodeData = @{
        '@Type' = 'PSMapNode'
        AzureAD = @{
            '@Type' = 'PSMapNode'
            AuthenticationMethodPolicy = @(
                @{
                    '@Type' = 'PSMapNode'
                    DefaultLength = @{ '@Type' = 'Int' }
                    DefaultLifetimeInMinutes = @{ '@Type' = 'Int' }
                    Ensure = @{ '@Type' = 'String' }
                    Id = @{ '@Type' = 'String' }
                    IncludeTargets = @(
                        @{
                            '@Type' = 'PSMapNode'
                            Id = @{ '@Type' = 'String' }
                            TargetType = @{ '@Type' = 'String' }
                        }
                    )
                    IsUsableOnce = @{ '@Type' = 'Bool' }
                    MaximumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    MinimumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    State = @{ '@Type' = 'String' }
                }
            )
        }
    }
}

$result = $data | Test-Object $schema
$result

Output:

Path                                           Value                                      Valid Issue
----                                           -----                                      ----- -----
NonNodeData.AzureAD.AuthenticationMethodPolicy @(@{IncorrectPr…=…;…},@{IncorrectPr…=…;…})  [X]  The following nodes are not accepted: 0, 1
NonNodeData.AzureAD                            @{Authenticat…=@(…)}                        [X]  The following nodes are not accepted: Authenticat…
NonNodeData                                    @{AzureAD=@{Authenticat…=…}}                [X]  The following nodes are not accepted: AzureAD

Here I would have expected two additional lines at the top with like this:

```PowerShell
Path                                              Value                                      Valid Issue
----                                              -----                                      ----- -----
NonNodeData.AzureAD.AuthenticationMethodPolicy[1] @{IncorrectPr…=10;IncorrectPr…=8}           [X]  The following nodes are not accepted: IncorrectPr…, IncorrectPr…
NonNodeData.AzureAD.AuthenticationMethodPolicy[0] @{IncorrectPr…=10;IncorrectPr…=8}           [X]  The following nodes are not accepted: IncorrectPr…, IncorrectPr…
NonNodeData.AzureAD.AuthenticationMethodPolicy    @(@{IncorrectPr…=…;…},@{DefaultLeng…=…;…})  [X]  The following nodes are not accepted: 0
NonNodeData.AzureAD                               @{Authenticat…=@(…)}                        [X]  The following nodes are not accepted: Authenticat…
NonNodeData                                       @{AzureAD=@{Authenticat…=…}}                [X]  The following nodes are not accepted: AzureAD
                                                  @{NonNodeData=@{AzureAD=…}}                 [X]  The following nodes are not accepted: NonNodeData

However, when using the -Elaborate parameter, these failing parameters are mentioned in the output, with all other output. So somehow they are filtered when not specifying that parameter.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions