Skip to content

Commit

Permalink
(chocolatey#2815) Add Pester tests for choco feature get
Browse files Browse the repository at this point in the history
This commit adds new end to end tests for the new choco feature get
command so ensure that it works as expected. This includes running both
choco feature and choco features, as well as running with --name and
without.
  • Loading branch information
gep13 committed Apr 14, 2023
1 parent 4df37a7 commit 4d224d5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/chocolatey-tests/commands/choco-feature.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, FeatureCommand {
Initialize-ChocolateyTestInstall

New-ChocolateyInstallSnapshot

$InitialConfiguration = ([xml](Get-Content $env:ChocolateyInstall\config\chocolatey.config)).chocolatey
$expectedLicenseHeader = Get-ExpectedChocolateyHeader
}

AfterAll {
Expand Down Expand Up @@ -214,6 +217,58 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, FeatureCommand {
}
}

Context "Getting a feature (<_.Name>)" -ForEach $CurrentFeatures {
BeforeAll {
$Output = Invoke-Choco feature get $_.Name
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It "Displays chocolatey name with version" {
$Output.Lines | Should -Contain $expectedLicenseHeader
}

It "Displays value of feature" {
$expectedResult = If ($InitialConfiguration.SelectSingleNode("//features/feature[@name='$($_.Name)']").enabled -eq "true" ) { "Enabled" } Else { "Disabled" }
$Output.Lines | Should -Contain $expectedResult -Because $Output.String
}
}

Context "Getting a feature by argument (<_.Name>)" -ForEach $CurrentFeatures {
BeforeAll {
$Output = Invoke-Choco feature get --name $_.Name
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It "Displays chocolatey name with version" {
$Output.Lines | Should -Contain $expectedLicenseHeader
}

It "Displays value of feature" {
$expectedResult = If ($InitialConfiguration.SelectSingleNode("//features/feature[@name='$($_.Name)']").enabled -eq "true" ) { "Enabled" } Else { "Disabled" }
$Output.Lines | Should -Contain $expectedResult -Because $Output.String
}
}

Context "Getting a feature that doesn't exist" {
BeforeAll {
$Output = Invoke-Choco feature get noFeatureValue
}

It "Exits with failure (1)" {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}

It "Outputs an error indicating that there's no feature by that name" {
$Output.Lines | Should -Contain "No feature value by the name 'noFeatureValue'"
}
}

# This needs to be the last test in this block, to ensure NuGet configurations aren't being created.
Test-NuGetPaths
}

0 comments on commit 4d224d5

Please sign in to comment.