Skip to content

Commit

Permalink
(#2872) Add end to end tests for [A] prompt action
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 committed Dec 5, 2022
1 parent 2f4fee9 commit edcf0be
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 12 deletions.
30 changes: 30 additions & 0 deletions tests/chocolatey-tests/commands/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1594,4 +1594,34 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$Output.Lines | Should -Contain "$($_ -replace '<installPath>',$env:ChocolateyInstall)" -Because $Output.String
}
}


Context "Installing multiple packages at once without allowGlobalConfirmation" {

BeforeAll {
Restore-ChocolateyInstallSnapshot
Disable-ChocolateyFeature -Name allowGlobalConfirmation

$PackageUnderTest = "installpackage", "packagewithscript"

$Output = "a`n"*2 | Invoke-Choco install @PackageUnderTest
}

It "Installs successfully and exits with success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Installed the packages to the lib directory" {
$PackageUnderTest | ForEach-Object {
"$env:ChocolateyInstall\lib\$_" | Should -Exist
}
}

It "Ran both installation scripts after selecting [A] Yes to all at the first prompt" {
$promptLine = "Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint):"
$prompts = $Output.Lines | Where-Object { $_.Trim() -eq $promptLine }

$prompts.Count | Should -Be 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>packagewithscript</id>
<version>1.0.0</version>
<title>packagewithscript</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>packagewithscript</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Before Modification"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "Installing $env:PackageName $env:PackageVersion"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
39 changes: 27 additions & 12 deletions tests/helpers/common/Chocolatey/Invoke-Choco.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,34 @@
param(
# The arguments to use when calling the Choco executable
[Parameter(Position = 1, ValueFromRemainingArguments)]
[string[]]$Arguments
)
[string[]]$Arguments,

$chocoPath = Get-ChocoPath
# Pipeline input to direct into choco.exe. Used mainly to "respond" to prompts
# in a noninteractive context. Provide input as a single string with line-feed
# characters ("`n") between input characters in that context.
[Parameter(ValueFromPipeline)]
[string]$PipelineInput
)
begin {
$chocoPath = Get-ChocoPath
$firstArgument, [string[]]$remainingArguments = $Arguments
$arguments = @($firstArgument; '--allow-unofficial'; $remainingArguments)
$output = & $chocoPath @arguments
[PSCustomObject]@{
# We trim all the lines, so we do not take into account
# trimming the lines when asserting, and that extra whitespace
# is not considered in our assertions.
Lines = if ($output) { $output.Trim() } else { @() }
String = $output -join "`r`n"
ExitCode = $LastExitCode
$arguments = @($firstArgument; '--allow-unofficial'; $remainingArguments)
}
end {
$output = if ($PipelineInput) {
$PipelineInput | & $chocoPath @arguments
}
else {
& $chocoPath @arguments
}

[PSCustomObject]@{
# We trim all the lines, so we do not take into account
# trimming the lines when asserting, and that extra whitespace
# is not considered in our assertions.
Lines = if ($output) { $output.Trim() } else { @() }
String = $output -join "`r`n"
ExitCode = $LastExitCode
}
}
}

0 comments on commit edcf0be

Please sign in to comment.