Skip to content

Commit

Permalink
Temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Sep 21, 2022
1 parent 48c8a5f commit 3c73b17
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
// If skipping hook scripts, return an empty list
if (configuration.SkipHookScripts) return hookScriptPaths;

// If hooks directory doesn't exist, return an empty list to prevent directory not exist warnings
if (!_fileSystem.directory_exists(ApplicationParameters.HooksLocation)) return hookScriptPaths;

string filenameBase;

if (isPreHook)
Expand Down
93 changes: 93 additions & 0 deletions tests/chocolatey-tests/Hooks.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Import-Module helpers/common-helpers

Describe "hooks tests" -Tag Chocolatey, Hooks {
BeforeDiscovery {
$Flags = @(
@{ Flag = '' ; RunsHooks = $true ; Command = 'install' }
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'install' }
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'install' }

@{ Flag = '' ; RunsHooks = $true ; Command = 'uninstall' }
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'uninstall' }
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'uninstall' }

@{ Flag = '' ; RunsHooks = $true ; Command = 'upgrade' }
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'upgrade' }
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'upgrade' }

)
}
BeforeAll {
Initialize-ChocolateyTestInstall
# Add the hooks package to the test install so that it is available in each snapshot.
$null = Invoke-Choco install scriptpackage.hook --version 1.0.0
New-ChocolateyInstallSnapshot
}

AfterAll {
Remove-ChocolateyTestInstall
}

Context '<Command> hooks with flag: <Flag>' -ForEach $Flags {
BeforeAll {
Restore-ChocolateyInstallSnapshot
$Package = 'upgradepackage'

if ($Command -ne 'install') {
$ver = if ($Command -eq 'upgrade') {
'1.0.0'
}
else {
'1.1.0'
}
$null = Invoke-Choco install $Package --version $ver --no-progress
}

$Output = Invoke-Choco $Command $Package $Flag --no-progress
}

# Uninstall/Upgrade exit -1: https://github.com/chocolatey/choco/issues/2822
It "Exits with Success (0,-1)" {
$Output.ExitCode | Should -BeIn @(0, -1) -Because $Output.String
}

It "Should execute hooks (<RunsHooks>)" {
$Version = '1.1.0'

$Messages = @(
if ($Command -eq 'uninstall') {
"pre-uninstall-all.ps1 hook ran for $Package $Version"
"post-uninstall-all.ps1 hook ran for $Package $Version"
"pre-uninstall-$Package.ps1 hook ran for $Package $Version"
"post-uninstall-$Package.ps1 hook ran for $Package $Version"
"pre-beforemodify-all.ps1 hook ran for $Package $Version"
"post-beforemodify-all.ps1 hook ran for $Package $Version"
"pre-beforemodify-$Package.ps1 hook ran for $Package $Version"
"post-beforemodify-$Package.ps1 hook ran for $Package $Version"
}
else {
"pre-install-all.ps1 hook ran for $Package $Version"
"post-install-all.ps1 hook ran for $Package $Version"
"pre-install-$Package.ps1 hook ran for $Package $Version"
"post-install-$Package.ps1 hook ran for $Package $Version"
}

if ($Command -eq 'upgrade') {
"pre-beforemodify-all.ps1 hook ran for $Package 1.0.0"
"pre-beforemodify-$Package.ps1 hook ran for $Package 1.0.0"
}
)

foreach ($msg in $Messages) {
if ($RunsHooks) {
$Output.Lines | Should -Contain $msg -Because $Output.String
}
else {
$Output.Lines | Should -Not -Contain $msg -Because $Output.String
}
}

$Output.Lines | Should -Not -Contain "pre-$Command-doesnotexist.ps1 hook ran for $Package $Version" -Because $Output.String
}
}
}
1 change: 1 addition & 0 deletions tests/chocolatey-tests/choco-info.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Describe "choco info" -Tag Chocolatey, InfoCommand {

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

$Output = Invoke-Choco info 'isdependency' --local-only
Expand Down
10 changes: 8 additions & 2 deletions tests/chocolatey-tests/choco-upgrade.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,22 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
Context "Upgrade package with (<Command>) specified" -ForEach @(
@{ Command = '--pin' ; Contains = $true }
@{ Command = '' ; Contains = $false }
) -Tag Mine {
) -tag mine {
BeforeAll {
Restore-ChocolateyInstallSnapshot -SetWorkDir

$Package = 'upgradepackage'
$null = Invoke-Choco install $Package --version 1.0.0 --confirm
$null = Invoke-Choco upgrade $Package $Command --confirm
$hmmm = Invoke-Choco upgrade $Package $Command --confirm
write-host $hmmm.string
write-host $hmmm.ExitCode
$Output = Invoke-Choco pin list
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Output should include pinned package" {
if ($Contains) {
$Output.Lines | Should -Contain "$Package|1.1.0"
Expand Down

0 comments on commit 3c73b17

Please sign in to comment.