From 4d224d5b7931b0fa8a8e5e4c4a3f28c0d23efd0f Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Fri, 14 Apr 2023 10:02:16 +0100 Subject: [PATCH] (#2815) Add Pester tests for choco feature get 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. --- .../commands/choco-feature.Tests.ps1 | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/chocolatey-tests/commands/choco-feature.Tests.ps1 b/tests/chocolatey-tests/commands/choco-feature.Tests.ps1 index 150eef7b1a..8f56cd1439 100644 --- a/tests/chocolatey-tests/commands/choco-feature.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-feature.Tests.ps1 @@ -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 { @@ -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 }