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 Pester Tests to Support branch #1035

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
(#956) Add initial set of Pester tests
Since we have a CLI for Chocolatey GUI, add some basic tests to ensure
it runs. This first set will only catch the most egregious errors, but
we can expand on them as we go.
  • Loading branch information
corbob committed Dec 21, 2023
commit d962bb5a3ad891ff0deb85fb41da5404c2c22fc5
49 changes: 49 additions & 0 deletions Tests/chocolateyguicli.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Import-Module helpers/gui-helpers

Describe "chocolateyguicli" -Tag ChocolateyGuiCli {
BeforeDiscovery {
# Perhaps a better way is to pull these from the LiteDB similar to how we do features from the xml in CLI, but this will do for an initial setup.
$Features = (Invoke-GuiCli feature list -r).Lines | ConvertFrom-Csv -Delimiter '|' -Header Name, state, description | Select-Object Name, @{Name = 'enabled'; Expression = { $_.state -eq 'Enabled' } }
$Features | Out-string | write-host
}

Context "Basic CLI functionality" {
BeforeAll {
$Output = Invoke-GuiCli
}

It 'Should exit Success (0)' {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It 'Should output appropriate message' {
$Output.Lines | Should -Contain "Please run chocolateyguicli with 'chocolateyguicli -?' or 'chocolateyguicli <command> -?' for specific help on each command"
}
}

Context "Lists available features" {
BeforeAll {
$Output = Invoke-GuiCli feature list
}

It "Contains reference of the option (<_.Name>)" -ForEach $Features {
$Output.String | Should -Match $Name
}
}

Context "Toggles the feature (<_.Name>) successfully" -ForEach $Features {
BeforeAll {
$Outputs = if ($Enabled) {
Invoke-GuiCli feature disable --name $_.Name
Invoke-GuiCli feature enable --name $_.Name
} else {
Invoke-GuiCli feature enable --name $_.Name
Invoke-GuiCli feature disable --name $_.Name
}
}

It "Should exit success" {
$Outputs.ExitCode | Should -Not -Contain 1
}
}
}
1 change: 1 addition & 0 deletions Tests/helpers/gui-helpers.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Get-ChildItem -Path $PSScriptRoot\gui -Filter *.ps1 -Recurse | ForEach-Object { . $_.FullName }
23 changes: 23 additions & 0 deletions Tests/helpers/gui/Invoke-GuiCli.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function Invoke-GuiCli {
<#
.Synopsis
Helper function to call chocolatey with any number of specified arguments,
and return a hashtable with the output as well as the exit code.
#>
[CmdletBinding()]
param(
# The arguments to use when calling the Choco executable
[Parameter(Position = 1, ValueFromRemainingArguments)]
[string[]]$Arguments
)

$output = & chocolateyguicli.exe @arguments
[PSCustomObject]@{
# We trim all the lines, so we do not take into account
# trimming the lines when asserting, and that extra whitespace
# is not considered in our assertions.
Lines = if ($output) { $output.Trim() } else { @() }
String = $output -join "`r`n"
ExitCode = $LastExitCode
}
}