chocolatey / cChoco

Community resource to manage Chocolatey
Apache License 2.0
154 stars 99 forks source link

(GH-148) Updates Tests to be compatible with Pester 5 #163

Closed JPRuskin closed 1 year ago

JPRuskin commented 2 years ago

Description

These commits update the tests to be compatible with Pester 5, as well as making some small maintenance commits to correct issues raised by the tests, e.g. trailing whitespace, unused parameters, etc. No tests were removed.

Related Issue

Fixes #148

Motivation and Context

This will allow us to use Pester 5 going forward. It should also result in easier addressing of PSSA test failures, as the new method (thanks to Jaykul) gives explicit failures with filepaths and line numbers.

How Has This Been Tested?

Primary testing was performed on a clean docker image running mcr.microsoft.com/powershell, without Chocolatey installed. Tests were also run on a Windows 10 machine, with Chocolatey installed, and are passing on AppVeyor. The tests now work with Chocolatey there or not, and other than the xDscResource tests work without elevation. This should be great for future users wanting to add to the tests!

Screenshots (if appropriate):

image

Example of old PSSA failures, taken from another PR:

[-] passes the PSScriptAnalyzer Rule PSShouldProcess 986ms
Expected 0, but got 1.
[-] passes the PSScriptAnalyzer Rule PSShouldProcess 986ms
Expected 0, but got 1.
34: (Invoke-ScriptAnalyzer -Path $module.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
at , C:\projects\cchoco\tests\cChoco_ScriptAnalyzerTests.ps1: line 3434: (Invoke-ScriptAnalyzer -Path $module.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
at , C:\projects\cchoco\tests\cChoco_ScriptAnalyzerTests.ps1: line 34

Example of new PSSA failures: image

Types of changes

Checklist:

Notes: There's no current contributing document that I can see. I also think I've changed the code style of the tests a little, but I think this is in the spirit of the issue.

corbob commented 1 year ago

Thanks for getting this added @JPRuskin 👍