Skip to content

Commit b63b96a

Browse files
authored
Merge pull request #2830 from corbob/a886_packages_config
2 parents 63c8cbd + 9062644 commit b63b96a

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
771771
}
772772
packageConfig.DownloadChecksum = string.IsNullOrWhiteSpace(pkgSettings.DownloadChecksum) ? packageConfig.DownloadChecksum : pkgSettings.DownloadChecksum;
773773
packageConfig.DownloadChecksum64 = string.IsNullOrWhiteSpace(pkgSettings.DownloadChecksum64) ? packageConfig.DownloadChecksum64 : pkgSettings.DownloadChecksum64;
774-
packageConfig.DownloadChecksum = string.IsNullOrWhiteSpace(pkgSettings.DownloadChecksumType) ? packageConfig.DownloadChecksumType : pkgSettings.DownloadChecksumType;
774+
packageConfig.DownloadChecksumType = string.IsNullOrWhiteSpace(pkgSettings.DownloadChecksumType) ? packageConfig.DownloadChecksumType : pkgSettings.DownloadChecksumType;
775775
packageConfig.DownloadChecksumType64 = string.IsNullOrWhiteSpace(pkgSettings.DownloadChecksumType64) ? packageConfig.DownloadChecksumType : pkgSettings.DownloadChecksumType64;
776776
if (pkgSettings.IgnorePackageExitCodes) packageConfig.Features.UsePackageExitCodes = false;
777777
if (pkgSettings.UsePackageExitCodes) packageConfig.Features.UsePackageExitCodes = true;
@@ -793,6 +793,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
793793

794794
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames));
795795
packageConfigs.Add(packageConfig);
796+
this.Log().Debug(() => "Package Configuration: {0}".format_with(packageConfig.ToString()));
796797
}
797798
}
798799

tests/chocolatey-tests/commands/choco-install.Tests.ps1

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,123 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
199199
It "Outputs a message indicating that missingpackage was not installed" {
200200
$Output.Lines | Should -Contain "missingpackage not installed. The package was not found with the source(s) listed."
201201
}
202+
203+
Context "packages.config containing all options" {
204+
BeforeAll {
205+
@"
206+
<?xml version="1.0" encoding="utf-8"?>
207+
<packages>
208+
<package
209+
id="installpackage"
210+
prerelease="true"
211+
overrideArguments="true"
212+
notSilent="true"
213+
allowDowngrade="true"
214+
forceDependencies="true"
215+
skipAutomationScripts="true"
216+
user="user"
217+
password="string"
218+
cert="cert"
219+
certPassword="string"
220+
ignoreChecksums="true"
221+
allowEmptyChecksums="true"
222+
allowEmptyChecksumsSecure="true"
223+
requireChecksums="true"
224+
downloadChecksum="downloadChecksum"
225+
downloadChecksum64="downloadChecksum64"
226+
downloadChecksumType="downloadChecksumType"
227+
downloadChecksumType64="downloadChecksumType64"
228+
ignorePackageExitCodes="true"
229+
usePackageExitCodes="true"
230+
stopOnFirstFailure="true"
231+
exitWhenRebootDetected="true"
232+
ignoreDetectedReboot="true"
233+
disableRepositoryOptimizations="true"
234+
acceptLicense="true"
235+
confirm="true"
236+
limitOutput="true"
237+
cacheLocation="Z:\"
238+
failOnStderr="true"
239+
useSystemPowershell="true"
240+
noProgress="true"
241+
force="true"
242+
executionTimeout="1000"
243+
/>
244+
</packages>
245+
"@ | Out-File $env:CHOCOLATEY_TEST_PACKAGES_PATH\alloptions.packages.config -Encoding utf8
246+
247+
$Output = Invoke-Choco install $env:CHOCOLATEY_TEST_PACKAGES_PATH\alloptions.packages.config --confirm --verbose --debug
248+
249+
# This is based on two observations: The addition explicitly outputs that it's the Package Configuration.
250+
# The configuration output is also about 80 lines.
251+
$StartofPackageConfiguration = [array]::IndexOf($Output.Lines, "Package Configuration: CommandName='install'|")
252+
$PackageConfigurationOutput = $Output.Lines[$StartofPackageConfiguration..($StartofPackageConfiguration+80)] -join [Environment]::NewLine
253+
}
254+
255+
# We are explicitly passing in a bad username and password here.
256+
# Therefore it cannot find the package to install and fails the install.
257+
# That doesn't matter because we just need to test that the configuration is set properly.
258+
It "Should exit Failure (1)" {
259+
$Output.ExitCode | Should -Be 1 -Because $Output.String
260+
}
261+
262+
It "Should contain the expected configuration option (<Option>) set correctly (<ExpectedValue>)" -ForEach @(
263+
@{ Option = "Prerelease" ; ExpectedValue = "True" }
264+
@{ Option = "OverrideArguments" ; ExpectedValue = "True" }
265+
@{ Option = "NotSilent" ; ExpectedValue = "True" }
266+
@{ Option = "AllowDowngrade" ; ExpectedValue = "True" }
267+
@{ Option = "ForceDependencies" ; ExpectedValue = "True" }
268+
# SkipAutomationScripts sets configuration option SkipPackageInstallProvider
269+
@{ Option = "SkipPackageInstallProvider" ; ExpectedValue = "True" }
270+
# User is expanded to Username
271+
@{ Option = "Username" ; ExpectedValue = "user" }
272+
# Password should *not* be output in the logging
273+
# @{ Option = "Password" ; ExpectedValue = "string" }
274+
# Cert is expanded to Certificate
275+
@{ Option = "Certificate" ; ExpectedValue = "cert" }
276+
# CertPassword should *not* be output in the logging
277+
# @{ Option = "CertPassword" ; ExpectedValue = "string" }
278+
# IgnoreChecksums sets ChecksumFiles to False
279+
@{ Option = "ChecksumFiles" ; ExpectedValue = "False" }
280+
# RequireChecksums is evaluated after allowing empty. It sets both allow options to False
281+
# @{ Option = "RequireChecksums" ; ExpectedValue = "True" }
282+
@{ Option = "AllowEmptyChecksums" ; ExpectedValue = "False" }
283+
@{ Option = "AllowEmptyChecksumsSecure" ; ExpectedValue = "False" }
284+
@{ Option = "DownloadChecksum" ; ExpectedValue = "downloadChecksum" }
285+
@{ Option = "DownloadChecksum64" ; ExpectedValue = "downloadChecksum64" }
286+
@{ Option = "DownloadChecksumType" ; ExpectedValue = "downloadChecksumType" }
287+
@{ Option = "DownloadChecksumType64" ; ExpectedValue = "downloadChecksumType64" }
288+
# UsePackageExitCodes and IgnorePackageExitCodes set the same setting, but are opposite of each other.
289+
# UsePackageExitCodes is evaluated last, so takes precidence.
290+
# @{ Option = "IgnorePackageExitCodes" ; ExpectedValue = "True" }
291+
@{ Option = "UsePackageExitCodes" ; ExpectedValue = "True" }
292+
# StopOnFirstFailure is expanded to StopOnFirstPackageFailure
293+
@{ Option = "StopOnFirstPackageFailure" ; ExpectedValue = "True" }
294+
# ExitWhenRebootDetected and IgnoreDetectedReboot both set ExitOnRebootDetected.
295+
# IgnoreDetectedReboot is evaluated last, so takes precidence.
296+
# @{ Option = "ExitWhenRebootDetected" ; ExpectedValue = "True" }
297+
# @{ Option = "IgnoreDetectedReboot" ; ExpectedValue = "True" }
298+
@{ Option = "ExitOnRebootDetected" ; ExpectedValue = "False" }
299+
# DisableRepositoryOptimizations sets UsePackageRepositoryOptimizations to false
300+
@{ Option = "UsePackageRepositoryOptimizations" ; ExpectedValue = "False" }
301+
@{ Option = "AcceptLicense" ; ExpectedValue = "True" }
302+
# Confirm is negated into PromptForConfirmation
303+
@{ Option = "PromptForConfirmation" ; ExpectedValue = "False" }
304+
# LimitOutput is negated into Regular Output
305+
@{ Option = "RegularOutput" ; ExpectedValue = "False" }
306+
@{ Option = "CacheLocation" ; ExpectedValue = "Z:\\" }
307+
@{ Option = "FailOnStandardError" ; ExpectedValue = "True" }
308+
# UseSystemPowerShell sets UsePowerShellHost to False
309+
@{ Option = "UsePowerShellHost" ; ExpectedValue = "False" }
310+
# NoProgress sets ShowDownloadProgress to False
311+
@{ Option = "ShowDownloadProgress" ; ExpectedValue = "False" }
312+
@{ Option = "Force" ; ExpectedValue = "True" }
313+
# ExecutionTimeout is expanded to CommandExecutionTimeoutSeconds
314+
@{ Option = "CommandExecutionTimeoutSeconds" ; ExpectedValue = "1000" }
315+
) {
316+
$PackageConfigurationOutput | Should -Match "$Option='$ExpectedValue'"
317+
}
318+
}
202319
}
203320

204321
Context "Installing a Package that is already installed" {

0 commit comments

Comments
 (0)