diff --git a/tests/chocolatey-tests/features/ChocolateyFunctions.Tests.ps1 b/tests/chocolatey-tests/features/ChocolateyFunctions.Tests.ps1 new file mode 100644 index 000000000..777c302fb --- /dev/null +++ b/tests/chocolatey-tests/features/ChocolateyFunctions.Tests.ps1 @@ -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 ()' -ForEach $ConfigValues { + # Trim the output as Lines is trimmed. + $Output.Lines | Should -Contain "${Name}: $Value".Trim() -Because $Output.String + } + } +} diff --git a/tests/packages/getconfig/getconfig.nuspec b/tests/packages/getconfig/getconfig.nuspec new file mode 100755 index 000000000..9678f092e --- /dev/null +++ b/tests/packages/getconfig/getconfig.nuspec @@ -0,0 +1,17 @@ + + + + + getconfig + 1.0.0 + Chocolatey + getconfig + Chocolatey + Chocolatey + getconfig + Test package for using Get-ChocolateyConfigValue. + + + + + diff --git a/tests/packages/getconfig/tools/chocolateyinstall.ps1 b/tests/packages/getconfig/tools/chocolateyinstall.ps1 new file mode 100755 index 000000000..1a402b1e9 --- /dev/null +++ b/tests/packages/getconfig/tools/chocolateyinstall.ps1 @@ -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" +}