-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3113 from blami/fix-2345
(#2345) Avoid any trailing spaces after silentArgs
- Loading branch information
Showing
9 changed files
with
139 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
tests/packages/install-chocolateyinstallpackage-tests/chocolateyinstall.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This package purposely uses files that don't exists. | ||
# As such, we need to continue on error. | ||
$ErrorActionPreference = 'SilentlyContinue' | ||
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" | ||
$fileLocation = "$toolsDir\ConsoleApp1" | ||
$exeArgs = @{ | ||
packageName = $env:ChocolateyPackageName | ||
silentArgs = "/exe " | ||
fileType = 'exe' | ||
file = "$fileLocation.exe" | ||
} | ||
$msiArgs = @{ | ||
packageName = $env:ChocolateyPackageName | ||
silentArgs = "/qn " | ||
# msiexec will exit with 1619 when the file doesn't exist. | ||
validExitCodes = @(1619) | ||
fileType = 'msi' | ||
file = "$fileLocation.msi" | ||
} | ||
$msuArgs = @{ | ||
packageName = $env:ChocolateyPackageName | ||
silentArgs = "/quiet " | ||
# wusa will exit with 2 when the file doesn't exist. | ||
validExitCodes = @(2) | ||
fileType = 'msu' | ||
file = "$fileLocation.msu" | ||
} | ||
|
||
# Since the exe doesn't exist, Install-ChocolateyInstallPackage is expected to | ||
# throw an exception. We don't care if it throws, we care that it outputs the | ||
# correct parameters. | ||
try { | ||
Install-ChocolateyInstallPackage @exeArgs | ||
} catch {} | ||
Install-ChocolateyInstallPackage @msiArgs | ||
Install-ChocolateyInstallPackage @msuArgs | ||
|
||
# Set the chocolateyInstallArgument environment variable to mimic Chocolatey | ||
# setting this variable. | ||
$env:chocolateyInstallArguments = '/norestart ' | ||
try { | ||
Install-ChocolateyInstallPackage @exeArgs | ||
} catch {} | ||
Install-ChocolateyInstallPackage @msiArgs | ||
Install-ChocolateyInstallPackage @msuArgs |
15 changes: 15 additions & 0 deletions
15
...ages/install-chocolateyinstallpackage-tests/install-chocolateyinstallpackage-tests.nuspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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>install-chocolateyinstallpackage-tests</id> | ||
<authors>Chocolatey Software</authors> | ||
<version>1.0</version> | ||
<title>Install-ChocolateyInstallPackage tests</title> | ||
<summary>Package for the testing of Install-ChocolateyInstallPackage</summary> | ||
<description>Package for the testing of Install-ChocolateyInstallPackage. Used by Pester to ensure extra spaces are not added to command lines.</description> | ||
</metadata> | ||
<files> | ||
<file src="chocolateyInstall.ps1" target="tools/chocolateyInstall.ps1" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/pester-tests/commands/Install-ChocolateyInstallPackage.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Describe 'Testing Install-ChocolateyInstallPackage' { | ||
BeforeDiscovery { | ||
# These tests are explicitly testing some scenarios that are not immediately | ||
# obvious. The test package sets 'SilentArguments' to a flag with a trailing space. | ||
# This is being tested both with and without Chocolatey adding additional | ||
# arguments. The package also sets the ChocolateyAdditionalArguments | ||
# environment variable to a string also with a trailing space. | ||
# Using exe as an example, that means the arguments passed are expected to be `/exe ` and then `/exe /norestart ` (Note the extra spaces in both instances). | ||
$ExpectedOutput = @( | ||
@{ | ||
OutputWithoutAdditionalArguments = '\["C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.exe" /exe \]' | ||
OutputWithAdditionalArguments = '\["C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.exe" /exe /norestart \]' | ||
Type = 'exe' | ||
} | ||
@{ | ||
OutputWithoutAdditionalArguments = '\["C:\\Windows\\System32\\msiexec.exe" /i "C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.msi" /qn \]' | ||
OutputWithAdditionalArguments = '\["C:\\Windows\\System32\\msiexec.exe" /i "C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.msi" /qn /norestart \]' | ||
Type = 'msi' | ||
} | ||
@{ | ||
OutputWithoutAdditionalArguments = '\["C:\\Windows\\System32\\wusa.exe" "C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.msu" /quiet \]' | ||
OutputWithAdditionalArguments = '\["C:\\Windows\\System32\\wusa.exe" "C:\\.*\\lib\\install-chocolateyinstallpackage-tests\\tools\\ConsoleApp1.msu" /quiet /norestart \]' | ||
Type = 'msu' | ||
} | ||
) | ||
} | ||
|
||
BeforeAll { | ||
Initialize-ChocolateyTestInstall | ||
$PackageUnderTest = 'install-chocolateyinstallpackage-tests' | ||
Restore-ChocolateyInstallSnapshot | ||
$Output = Invoke-Choco install $PackageUnderTest --confirm --debug | ||
} | ||
|
||
AfterAll { | ||
Remove-ChocolateyInstallSnapshot | ||
} | ||
|
||
It 'Exits with Success (0)' { | ||
$Output.ExitCode | Should -Be 0 -Because $Output.String | ||
} | ||
|
||
It 'Output is accurate for installer type <Type>' -ForEach $ExpectedOutput { | ||
$Output.String | Should -MatchExactly $OutputWithoutAdditionalArguments -Because ($Output.Lines | Select-String "ConsoleApp1.$Type") | ||
$Output.String | Should -MatchExactly $OutputWithAdditionalArguments -Because ($Output.Lines | Select-String "ConsoleApp1.$Type") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters