microsoft / winget-dsc

MIT License
24 stars 14 forks source link

Add some tests for GitDsc #87

Closed Trenly closed 2 weeks ago

Trenly commented 3 weeks ago

I noticed that the GitConfigFile resource in the GitDsc module didn't actually exist. So, I removed it and added the test for listing the available resources. I also added a basic test for the GitClone resource. I wasn't familiar enough with the other resources in the module to add tests for them, but I figured that some tests were better than none. If this PR merges, I'll raise an issue for tracking that the additional tests should be added


ryfu-msft commented 3 weeks ago

/azp run

azure-pipelines[bot] commented 3 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).
Trenly commented 3 weeks ago

o.O They ran locally for me. . . Time to debug!

ryfu-msft commented 3 weeks ago

o.O They ran locally for me. . . Time to debug!

You might need to rearrange the order so that the helper functions are first before the Assert-Git

Trenly commented 3 weeks ago

I think the issue is actually that Git just isn't installed, so there is no way for it to actually clone the repository. I think this leaves 2 options - 1) Have the tests install Git using Microsoft.WinGet.DSC 2) Have some test data or test files that can be copied to the directory in place of asserting that the actual process of running git clone works

Edit: Just realized that option 2 won't work, since that also requires git to be installed 🤦

Trenly commented 3 weeks ago

Okay, that was harder than I thought it would be, since Pester doesn't like to play nice if you don't have the scopes set juuuuuust right, but I think I got it to work

ryfu-msft commented 3 weeks ago

/azp run

azure-pipelines[bot] commented 3 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).
ryfu-msft commented 3 weeks ago

/azp run

azure-pipelines[bot] commented 3 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).
Trenly commented 3 weeks ago

Okay, now I'm truly lost. This is the error on line 22 -

##[error] [-] Discovery in D:\a\_work\1\s\tests\GitDsc\GitDsc.Tests.ps1 failed with:
##[error] System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The 'Assert-Git' command was found in the module 'GitDsc', but the module could not be loaded. For more information, run 'Import-Module GitDsc'.

But yet the module is imported on line 19 in the BeforeAll block ???

Edit: When the module is imported, it calls Assert-Git. That assertion fails because Git is not installed in the pipelines. The failed assertion throws, which causes Pester to not be able to bind into the container

ryfu-msft commented 2 weeks ago

/azp run

azure-pipelines[bot] commented 2 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).
ryfu-msft commented 2 weeks ago

/azp run

azure-pipelines[bot] commented 2 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).
Trenly commented 2 weeks ago

Why do I even try. I uninstalled Git, and the tests passed for me. I tried it in a VM, and the tests passed for me. I have no clue what's going wrong. I'll revisit this later once I have a bit more time