Skip to content

Commit 63c8cbd

Browse files
authored
Merge pull request chocolatey#2823 from corbob/a798-pin-package
2 parents d08d1f6 + 794bf67 commit 63c8cbd

File tree

68 files changed

+157
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+157
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
9191
// If skipping hook scripts, return an empty list
9292
if (configuration.SkipHookScripts) return hookScriptPaths;
9393

94+
// If hooks directory doesn't exist, return an empty list to prevent directory not exist warnings
95+
if (!_fileSystem.directory_exists(ApplicationParameters.HooksLocation)) return hookScriptPaths;
96+
9497
string filenameBase;
9598

9699
if (isPreHook)

tests/chocolatey-tests/chocolatey.Tests.ps1

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
139139

140140
# This is FossOnly for now as there are some undetermined errors here that do not seem to present inside of Chocolatey. https://gitlab.com/chocolatey/build-automation/chocolatey-test-kitchen/-/issues/39
141141
It "Should be able to run the script in AllSigned mode" -Skip:($_ -notin $PowerShellFiles) -Tag FossOnly {
142-
# The chocolateyScriptRunner expects some passed in values and results in two errors if they're not there. This accounts for that.
143-
$expectedErrors = if ($FileUnderTest.Name -eq 'chocolateyScriptRunner.ps1') {
144-
2
145-
}
146-
else {
147-
0
148-
}
142+
$expectedErrors = 0
149143
$command = "Import-Module $FileUnderTest -ErrorAction SilentlyContinue; exit `$error.count"
150144
& powershell.exe -noprofile -ExecutionPolicy AllSigned -command $command 2>$null
151145
$LastExitCode | Should -BeExactly $expectedErrors

tests/chocolatey-tests/choco-info.Tests.ps1 renamed to tests/chocolatey-tests/commands/choco-info.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Describe "choco info" -Tag Chocolatey, InfoCommand {
145145

146146
Context "Listing package information about local side by side installed package" {
147147
BeforeAll {
148+
Restore-ChocolateyInstallSnapshot
148149
$null = Invoke-Choco install 'isdependency' --confirm --sxs
149150

150151
$Output = Invoke-Choco info 'isdependency' --local-only

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
12821282
}
12831283

12841284
# Issue: https://github.com/chocolatey/chocolatey-licensed-issues/issues/284
1285-
Context "Installing a Package with Embedded Zip Archive and specifying destination <Name>" -Foreach @(
1285+
Context "Installing a Package with Embedded Zip Archive and specifying destination <Name>" -ForEach @(
12861286
@{ Name = 'Root of UNC share' ; Path = '\\localhost\c$\' }
12871287
@{ Name = 'UNC share path' ; Path = '\\localhost\c$\temp\' }
12881288
@{ Name = 'Root of drive with trailing slash' ; Path = 'C:\' }
@@ -1393,6 +1393,37 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
13931393
}
13941394
}
13951395

1396+
Context "Install '<Package>' package with (<Command>) specified" -ForEach @(
1397+
@{ Command = '--pin' ; Package = 'installpackage' ; Contains = $true }
1398+
@{ Command = '' ; Package = 'installpackage' ; Contains = $false }
1399+
@{ Command = '' ; Package = 'packages.config' ; Contains = $true }
1400+
) {
1401+
BeforeAll {
1402+
Restore-ChocolateyInstallSnapshot
1403+
1404+
if ($Package -eq 'packages.config') {
1405+
@"
1406+
<?xml version="1.0" encoding="utf-8"?>
1407+
<packages>
1408+
<package id="installpackage" pinPackage="true" />
1409+
</packages>
1410+
"@ | Set-Content $PWD/packages.config
1411+
}
1412+
1413+
$null = Invoke-Choco install $Package $Command --confirm
1414+
$Output = Invoke-Choco pin list
1415+
}
1416+
1417+
It "Output should include pinned package" {
1418+
if ($Contains) {
1419+
$Output.String | Should -Match "installpackage|1.0.0"
1420+
}
1421+
else {
1422+
$Output.String | Should -Not -Match "installpackage|1.0.0"
1423+
}
1424+
}
1425+
}
1426+
13961427
Context "Installing package that extracts local zip archive while disabling logging" {
13971428
BeforeAll {
13981429
Restore-ChocolateyInstallSnapshot

0 commit comments

Comments
 (0)