forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#2345) Add Pester tests to validate fix
This adds a set of tests to validate that the spaces that may be passed in by the package are honoured, while not introducing erroneous spaces.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
# 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 " | ||
validExitCodes = @(2,1619) | ||
fileType = 'exe' | ||
file = "$fileLocation.exe" | ||
} | ||
$msiArgs = @{ | ||
packageName = $env:ChocolateyPackageName | ||
silentArgs = "/qn " | ||
validExitCodes = @(2,1619) | ||
fileType = 'msi' | ||
file = "$fileLocation.msi" | ||
} | ||
$msuArgs = @{ | ||
packageName = $env:ChocolateyPackageName | ||
silentArgs = "/quiet " | ||
validExitCodes = @(2,1619) | ||
fileType = 'msu' | ||
file = "$fileLocation.msu" | ||
} | ||
|
||
|
||
try { | ||
Install-ChocolateyInstallPackage @exeArgs | ||
} catch {} | ||
Install-ChocolateyInstallPackage @msiArgs | ||
Install-ChocolateyInstallPackage @msuArgs | ||
$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> |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
Describe 'Testing Install-ChocolateyInstallPackage' -Tag Testing { | ||
BeforeDiscovery { | ||
$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") | ||
} | ||
} |