Skip to content

Commit

Permalink
(#2854) Pester tests to Get-ChocolateyConfigValue
Browse files Browse the repository at this point in the history
Add pester tests around the functionality added by
Get-ChocolateyConfigValue
  • Loading branch information
corbob committed Jun 20, 2023
1 parent 575fddb commit 2021987
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/chocolatey-tests/features/ChocolateyFunctions.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# These tests install packages that exercise the Chocolatey PowerShell functions
# TODO: Move some of the install tests into this file
Describe 'Chocolatey PowerShell functions' {
BeforeAll {
Initialize-ChocolateyTestInstall
}

Context 'Get-ChocolateyConfigValue' -ForEach @{
ConfigValues = @(
@{ Name = 'addedTextValue' ; Value = 'SomeTextValue' }
@{ Name = 'addedNumberValue' ; Value = 123456 }
@{ Name = 'commandExecutionTimeoutSeconds' ; Value = 2795 }
@{ Name = 'cacheLocation' ; Value = $null }
@{ Name = 'nonExistentKey' ; Value = $null }
)
} -Tag Get-ChocolateyConfigValue {

BeforeAll {
Restore-ChocolateyInstallSnapshot

foreach ($Value in $ConfigValues) {
if ($null -ne $Value.Value) {
Invoke-Choco config set --name $Value.Name --value $Value.Value
}
}

$Output = Invoke-Choco install getconfig --confirm
}

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

It 'Outputs the expected value for config entry (<Name>)' -ForEach $ConfigValues {
# Trim the output as Lines is trimmed.
$Output.Lines | Should -Contain "${Name}: $Value".Trim() -Because $Output.String
}
}
}
17 changes: 17 additions & 0 deletions tests/packages/getconfig/getconfig.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>getconfig</id>
<version>1.0.0</version>
<owners>Chocolatey</owners>
<title>getconfig</title>
<authors>Chocolatey</authors>
<copyright>Chocolatey</copyright>
<tags>getconfig</tags>
<description>Test package for using Get-ChocolateyConfigValue.</description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
14 changes: 14 additions & 0 deletions tests/packages/getconfig/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$ErrorActionPreference = 'Stop'

$ValuesToTest = @(
'addedTextValue'
'addedNumberValue'
'commandExecutionTimeoutSeconds'
'cacheLocation'
'nonExistentKey'
)

foreach ($Value in $ValuesToTest) {
$Result = Get-ChocolateyConfigValue -configKey $Value
Write-Host "${Value}: $Result"
}

0 comments on commit 2021987

Please sign in to comment.