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

Add Microsoft.Windows.Assertion Module #90

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Trenly
Copy link
Contributor

@Trenly Trenly commented Nov 2, 2024

Premise

Until DSC v3 is released, there isn't a good way to assert specific system parameters in DSC - Especially for use with WinGet. This module adds several different DSC Resources that can be used for asserting the state of a system, primarily for use in WinGet configuration files. This will allow DSC users in enterprises to target specific architectures, specific domain roles, computers with specific print servers, etc. by adding these assertions directly into their configuration YAML instead of having to push out a wrapper script that performs the checks before invoking the DSC, and without having to write their own implementations using the Script DSCResource.


@Trenly Trenly marked this pull request as ready for review November 4, 2024 19:56
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Author-Feedback This needs a response from the author. Needs-Attention This work item needs to be reviewed by a member of the core team and removed Needs-Author-Feedback This needs a response from the author. labels Nov 5, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed Changes-Requested Changes Requested Needs-Attention This work item needs to be reviewed by a member of the core team labels Nov 5, 2024

This comment has been minimized.

@Trenly Trenly marked this pull request as draft November 5, 2024 22:29
@Trenly Trenly marked this pull request as ready for review November 5, 2024 22:47
@Trenly Trenly requested a review from ryfu-msft November 5, 2024 22:47
@Trenly Trenly marked this pull request as draft November 5, 2024 23:01
@Trenly
Copy link
Contributor Author

Trenly commented Nov 5, 2024

Didn't realize I still have scriptanalyzer errors

@Trenly Trenly marked this pull request as ready for review November 6, 2024 00:44

This comment has been minimized.

@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly
Copy link
Contributor Author

Trenly commented Nov 11, 2024

Hmmmmmm

@Trenly
Copy link
Contributor Author

Trenly commented Nov 23, 2024

@ryfu-msft - I'm a bit stuck here and don't know how to go about it. When I run the pester tests locally, I see them pass -

PS E:\winget-dsc> Invoke-Pester E:\winget-dsc\tests\Microsoft.Windows.Assertion

Starting discovery in 1 files.
Discovery found 73 tests in 711ms.
Running tests.
[+] E:\winget-dsc\tests\Microsoft.Windows.Assertion\Microsoft.Windows.Assertion.Tests.ps1 5.3s (3.8s|814ms)
Tests completed in 5.33s
Tests Passed: 73, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
PS E:\winget-dsc> $env:COMPUTERNAME
CORSAIR-JLU545

I even went to a completely different computer, checked out the repo, and ran the tests, where they all passed.

PS C:\git\winget-dsc> Invoke-Pester C:\git\winget-dsc\tests\Microsoft.Windows.Assertion

Starting discovery in 1 files.
Discovery found 73 tests in 510ms.
Running tests.
[+] C:\git\winget-dsc\tests\Microsoft.Windows.Assertion\Microsoft.Windows.Assertion.Tests.ps1 17.3s (16.44s|347ms)      
Tests completed in 17.3s
Tests Passed: 73, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
PS C:\git\winget-dsc> $env:COMPUTERNAME
M5423133

Then, I used Invoke-DSCResource to manually test, and everything passed there; Granted I did have to use valid PnPDevices that were on my system for the cases where I expected it to match, but all of the ones that I expected to not match didn't match.

As a final effort, I opened up a new Windows Sandbox, mapped in the folder from Git, installed PowerShell 7, and tried running the tests. They all passed again -

PS C:\Users\WDAGUtilityAccount> Invoke-Pester C:\Users\WDAGUtilityAccount\Desktop\winget-dsc\tests\Microsoft.Windows.Assertion\

Starting discovery in 1 files.
Discovery found 73 tests in 715ms.
Running tests.
[+] C:\Users\WDAGUtilityAccount\Desktop\winget-dsc\tests\Microsoft.Windows.Assertion\Microsoft.Windows.Assertion.Tests.ps1 11.71s (10.33s|699ms)
Tests completed in 11.73s
Tests Passed: 73, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
PS C:\Users\WDAGUtilityAccount> $env:COMPUTERNAME
C1BE12D1-33D2-4

Can you help me understand why the pipelines are showing different results? Are they using a specific version of Pester?

@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Gijsreyn
Copy link
Contributor

Trenly, maybe this helps:

image

You can run it through Azure Pipelines itself. I had a similar problem, but this was related to a PowerShell module not being available on the hosted agents (see #120). If you want, you can always hit me up to give it a try. Cheers.

@Trenly
Copy link
Contributor Author

Trenly commented Dec 18, 2024

Trenly, maybe this helps:

Are you saying that the module for Get-PNPDevice isn't present? Because it seems to me the only reason it's failing is because the mocks are not applying. If the mocks were applying, you wouldn't see the CIM error

@Gijsreyn
Copy link
Contributor

Gijsreyn commented Dec 19, 2024

Trenly, maybe this helps:

Are you saying that the module for Get-PNPDevice isn't present? Because it seems to me the only reason it's failing is because the mocks are not applying. If the mocks were applying, you wouldn't see the CIM error

No, that's not actually what I was referring to. What I wanted to refer to is that I made an assumption that you hadn't tried running the test on an Azure Pipelines hosted agent. I have seen some strange cases now where some things are available on your local machine (or sandbox) but slightly behave differently on the hosted agents. That's why I wanted to run it through the agent itself and see what it was doing. The pipeline running in this repository doesn't always output the verbosity message you might have sought. And I think the Get-PnPDevice was there; otherwise, the other tests would have also failed.

P.S. The tests were run under Pester v5.6.1.


<#
.Synopsis
Pester tests related to the Microsoft.WinGet.Developer PowerShell module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should be Microsoft.WinGet.Assertion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants