Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix output of Assertion resource for test to resemble config and add support for array comparison #595

Merged
merged 10 commits into from
Nov 17, 2024

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Nov 8, 2024

PR Summary

Two problems addressed by this PR:

  • The output of Assertion simply returned the actual result to look like a get result, however, this causes the synthetic test doing a diff to fail as they don't resemble each other. To address this, added a new hidden switch --as--config to inform dsc that this is a special case and the output needs to be transformed to a Configuration so that the synthetic test can work.

Here's example of the new output:

metadata:
  Microsoft.DSC:
    version: 3.0.0
    operation: Test
    executionType: Actual
    startDatetime: 2024-11-07T16:45:48.237829-08:00
    endDatetime: 2024-11-07T16:45:48.789203-08:00
    duration: PT0.551374S
    securityContext: Restricted
results:
- metadata:
    Microsoft.DSC:
      duration: PT0.441752S
  name: Operating System Assertion
  type: Microsoft.DSC/Assertion
  result:
    desiredState:
      $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
      resources:
      - name: Is64BitOS
        type: Microsoft/OSInfo
        properties:
          bitness: '64'
      - name: 64bit test 2
        type: Microsoft/OSInfo
        properties:
          family: Windows
    actualState:
      $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
      resources:
      - type: Microsoft/OSInfo
        name: Is64BitOS
        properties:
          $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
          family: macOS
          version: 15.1.0
          bitness: '64'
          architecture: arm64
      - type: Microsoft/OSInfo
        name: 64bit test 2
        properties:
          $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
          family: macOS
          version: 15.1.0
          bitness: '64'
          architecture: arm64
    inDesiredState: false
    differingProperties:
    - resources
messages: []
hadErrors: false
  • The second issue is that the synthetic test didn't handle arrays at all and resources is always an array. Arrays need to be the same per the current diff rules:
    • same size
    • each element needs to exist
    • objects in actual can be superset of the expected

PR Context

Fix #165

@SteveL-MSFT SteveL-MSFT added this to the 3.0-Approved milestone Nov 8, 2024
@SteveL-MSFT SteveL-MSFT force-pushed the assert-array branch 3 times, most recently from f87a4eb to 8f499d7 Compare November 8, 2024 19:53
@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Nov 17, 2024
Merged via the queue into PowerShell:main with commit b52b5cb Nov 17, 2024
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the assert-array branch November 17, 2024 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DSC/AssertionGroup reports as out of state for test method even when all instances are in the desired state
3 participants