chocolatey / chocolatey/choco

Tests - Enhance Pester tests to standardize some boilerplate

Open
#2,712 0 comments 0 reactions 1 assignee Claimed by @corbob View on GitHub
1 - Ready Tests
Dominant language
C#
Stars
11.5k
Forks
961
PR merge metrics
No merged PRs in 30d

Description

## Is Your Feature Request Related To A Problem? Please describe.

Currently many of our tests include boilerplate for ensuring exit codes:

```powershell
It "should exit with Failure (1)" {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}
```

The trouble with this is if you update the exit code, but miss updating it in the block title, or miss labeling it as success, etc.

## Describe The Solution. Why is it needed?

Because we're just writing PowerShell, we can call our own function here. Propose adding a `Test-ChocolateyOutput` function to `common-helpers` so that you can call `Test-ChocolateyOutput -ExpectedExit 1 -Output $Output`, and then the boilerplate will be made for you, and the exit codes will match up, and the output will always be included in the because.

## Additional Context.

There are a few times where the exit code is expected to be in an array of known values (perhaps success, but requires a system reboot...). It would be beneficial to include those scenarios in this function, but may be done as a later task.

This issue is mostly for bringing in the function, and perhaps updating a few tests initially. Other tests can be updated as needed.

## Related Issues

None

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.