diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index e57e66b98e..0eff99c008 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -91,6 +91,9 @@ private IEnumerable 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) diff --git a/tests/chocolatey-tests/chocolatey.Tests.ps1 b/tests/chocolatey-tests/chocolatey.Tests.ps1 index b89d2d0ccb..de3a47c88a 100644 --- a/tests/chocolatey-tests/chocolatey.Tests.ps1 +++ b/tests/chocolatey-tests/chocolatey.Tests.ps1 @@ -139,13 +139,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat # 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 It "Should be able to run the script in AllSigned mode" -Skip:($_ -notin $PowerShellFiles) -Tag FossOnly { - # The chocolateyScriptRunner expects some passed in values and results in two errors if they're not there. This accounts for that. - $expectedErrors = if ($FileUnderTest.Name -eq 'chocolateyScriptRunner.ps1') { - 2 - } - else { - 0 - } + $expectedErrors = 0 $command = "Import-Module $FileUnderTest -ErrorAction SilentlyContinue; exit `$error.count" & powershell.exe -noprofile -ExecutionPolicy AllSigned -command $command 2>$null $LastExitCode | Should -BeExactly $expectedErrors diff --git a/tests/chocolatey-tests/choco-apikey.Tests.ps1 b/tests/chocolatey-tests/commands/choco-apikey.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-apikey.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-apikey.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-config.Tests.ps1 b/tests/chocolatey-tests/commands/choco-config.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-config.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-config.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-deprecated.Tests.ps1 b/tests/chocolatey-tests/commands/choco-deprecated.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-deprecated.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-deprecated.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-export.Tests.ps1 b/tests/chocolatey-tests/commands/choco-export.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-export.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-export.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-feature.Tests.ps1 b/tests/chocolatey-tests/commands/choco-feature.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-feature.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-feature.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-help.Tests.ps1 b/tests/chocolatey-tests/commands/choco-help.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-help.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-help.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-info.Tests.ps1 b/tests/chocolatey-tests/commands/choco-info.Tests.ps1 similarity index 96% rename from tests/chocolatey-tests/choco-info.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-info.Tests.ps1 index 81038b7432..1356d18aa9 100644 --- a/tests/chocolatey-tests/choco-info.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-info.Tests.ps1 @@ -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 diff --git a/tests/chocolatey-tests/choco-install.Tests.ps1 b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 similarity index 95% rename from tests/chocolatey-tests/choco-install.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-install.Tests.ps1 index 2a810317b5..e817259ceb 100644 --- a/tests/chocolatey-tests/choco-install.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 @@ -1282,7 +1282,7 @@ Describe "choco install" -Tag Chocolatey, InstallCommand { } # Issue: https://github.com/chocolatey/chocolatey-licensed-issues/issues/284 - Context "Installing a Package with Embedded Zip Archive and specifying destination " -Foreach @( + Context "Installing a Package with Embedded Zip Archive and specifying destination " -ForEach @( @{ Name = 'Root of UNC share' ; Path = '\\localhost\c$\' } @{ Name = 'UNC share path' ; Path = '\\localhost\c$\temp\' } @{ Name = 'Root of drive with trailing slash' ; Path = 'C:\' } @@ -1393,6 +1393,37 @@ Describe "choco install" -Tag Chocolatey, InstallCommand { } } + Context "Install '' package with () specified" -ForEach @( + @{ Command = '--pin' ; Package = 'installpackage' ; Contains = $true } + @{ Command = '' ; Package = 'installpackage' ; Contains = $false } + @{ Command = '' ; Package = 'packages.config' ; Contains = $true } + ) { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + if ($Package -eq 'packages.config') { + @" + + + + +"@ | Set-Content $PWD/packages.config + } + + $null = Invoke-Choco install $Package $Command --confirm + $Output = Invoke-Choco pin list + } + + It "Output should include pinned package" { + if ($Contains) { + $Output.String | Should -Match "installpackage|1.0.0" + } + else { + $Output.String | Should -Not -Match "installpackage|1.0.0" + } + } + } + Context "Installing package that extracts local zip archive while disabling logging" { BeforeAll { Restore-ChocolateyInstallSnapshot diff --git a/tests/chocolatey-tests/choco-list.Tests.ps1 b/tests/chocolatey-tests/commands/choco-list.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-list.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-list.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-new.Tests.ps1 b/tests/chocolatey-tests/commands/choco-new.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-new.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-new.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-outdated.Tests.ps1 b/tests/chocolatey-tests/commands/choco-outdated.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-outdated.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-outdated.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-pack.Tests.ps1 b/tests/chocolatey-tests/commands/choco-pack.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-pack.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-pack.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-pin.Tests.ps1 b/tests/chocolatey-tests/commands/choco-pin.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-pin.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-pin.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-push.Tests.ps1 b/tests/chocolatey-tests/commands/choco-push.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-push.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-push.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-removed.Tests.ps1 b/tests/chocolatey-tests/commands/choco-removed.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-removed.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-removed.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-source.Tests.ps1 b/tests/chocolatey-tests/commands/choco-source.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-source.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-source.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-template.Tests.ps1 b/tests/chocolatey-tests/commands/choco-template.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-template.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-template.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-uninstall.Tests.ps1 b/tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-uninstall.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 diff --git a/tests/chocolatey-tests/choco-upgrade.Tests.ps1 b/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 similarity index 89% rename from tests/chocolatey-tests/choco-upgrade.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 index 25b8d785fc..593c1fdee2 100644 --- a/tests/chocolatey-tests/choco-upgrade.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 @@ -120,6 +120,33 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand { } } + Context "Upgrade package with () specified" -ForEach @( + @{ Command = '--pin' ; Contains = $true } + @{ Command = '' ; Contains = $false } + ) { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Package = 'upgradepackage' + $null = Invoke-Choco install $Package --version 1.0.0 --confirm + $null = Invoke-Choco upgrade $Package $Command --confirm + $Output = Invoke-Choco pin list + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 + } + + It "Output should include pinned package" { + if ($Contains) { + $Output.String | Should -Match "$Package|1.1.0" + } + else { + $Output.String | Should -Not -Match "$Package|1.1.0" + } + } + } + Context "Upgrading packages while remembering arguments with only one package using arguments" -Tag Internal { BeforeAll { Restore-ChocolateyInstallSnapshot diff --git a/tests/chocolatey-tests/choco-version.Tests.ps1 b/tests/chocolatey-tests/commands/choco-version.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/choco-version.Tests.ps1 rename to tests/chocolatey-tests/commands/choco-version.Tests.ps1 diff --git a/tests/chocolatey-tests/testnuspecs/basic-dependencies/basic-dependencies.nuspec b/tests/chocolatey-tests/commands/testnuspecs/basic-dependencies/basic-dependencies.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/basic-dependencies/basic-dependencies.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/basic-dependencies/basic-dependencies.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/basic/basic.nuspec b/tests/chocolatey-tests/commands/testnuspecs/basic/basic.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/basic/basic.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/basic/basic.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/basic/tools/purpose.txt b/tests/chocolatey-tests/commands/testnuspecs/basic/tools/purpose.txt similarity index 100% rename from tests/chocolatey-tests/testnuspecs/basic/tools/purpose.txt rename to tests/chocolatey-tests/commands/testnuspecs/basic/tools/purpose.txt diff --git a/tests/chocolatey-tests/testnuspecs/cdata/cdata.nuspec b/tests/chocolatey-tests/commands/testnuspecs/cdata/cdata.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/cdata/cdata.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/cdata/cdata.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/description-long.nuspec b/tests/chocolatey-tests/commands/testnuspecs/description-long.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/description-long.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/description-long.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/empty-requireLicenseAcceptance.nuspec b/tests/chocolatey-tests/commands/testnuspecs/empty-requireLicenseAcceptance.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/empty-requireLicenseAcceptance.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/empty-requireLicenseAcceptance.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/empty.nuspec b/tests/chocolatey-tests/commands/testnuspecs/empty.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/empty.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/empty.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/forward-slash/forward-slash.nuspec b/tests/chocolatey-tests/commands/testnuspecs/forward-slash/forward-slash.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/forward-slash/forward-slash.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/forward-slash/forward-slash.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/forward-slash/tools/purpose.txt b/tests/chocolatey-tests/commands/testnuspecs/forward-slash/tools/purpose.txt similarity index 100% rename from tests/chocolatey-tests/testnuspecs/forward-slash/tools/purpose.txt rename to tests/chocolatey-tests/commands/testnuspecs/forward-slash/tools/purpose.txt diff --git a/tests/chocolatey-tests/testnuspecs/full/full.nuspec b/tests/chocolatey-tests/commands/testnuspecs/full/full.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/full/full.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/full/full.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/full/tools/purpose.txt b/tests/chocolatey-tests/commands/testnuspecs/full/tools/purpose.txt similarity index 100% rename from tests/chocolatey-tests/testnuspecs/full/tools/purpose.txt rename to tests/chocolatey-tests/commands/testnuspecs/full/tools/purpose.txt diff --git a/tests/chocolatey-tests/testnuspecs/invalid-bugtrackerurl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-bugtrackerurl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-bugtrackerurl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-bugtrackerurl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-character-and.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-character-and.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-character-and.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-character-and.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-character-lesser.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-character-lesser.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-character-lesser.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-character-lesser.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-docsurl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-docsurl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-docsurl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-docsurl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-iconurl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-iconurl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-iconurl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-iconurl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-id.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-id.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-id.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-id.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-licenseUrl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-licenseUrl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-licenseUrl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-licenseUrl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-mailinglisturl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-mailinglisturl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-mailinglisturl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-mailinglisturl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-no-content.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-no-content.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-no-content.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-no-content.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-projectsourceurl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-projectsourceurl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-projectsourceurl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-projectsourceurl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-projecturl.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-projecturl.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-projecturl.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-projecturl.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-requireLicenseAcceptance.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-requireLicenseAcceptance.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-requireLicenseAcceptance.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-requireLicenseAcceptance.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/invalid-version.nuspec b/tests/chocolatey-tests/commands/testnuspecs/invalid-version.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/invalid-version.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/invalid-version.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/missing.nuspec b/tests/chocolatey-tests/commands/testnuspecs/missing.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/missing.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/missing.nuspec diff --git a/tests/chocolatey-tests/testnuspecs/required.nuspec b/tests/chocolatey-tests/commands/testnuspecs/required.nuspec similarity index 100% rename from tests/chocolatey-tests/testnuspecs/required.nuspec rename to tests/chocolatey-tests/commands/testnuspecs/required.nuspec diff --git a/tests/chocolatey-tests/testpackages/.gitignore b/tests/chocolatey-tests/commands/testpackages/.gitignore similarity index 100% rename from tests/chocolatey-tests/testpackages/.gitignore rename to tests/chocolatey-tests/commands/testpackages/.gitignore diff --git a/tests/chocolatey-tests/testpackages/chocolatey-dummy-package/1.0.0/chocolatey-dummy-package.nuspec b/tests/chocolatey-tests/commands/testpackages/chocolatey-dummy-package/1.0.0/chocolatey-dummy-package.nuspec similarity index 100% rename from tests/chocolatey-tests/testpackages/chocolatey-dummy-package/1.0.0/chocolatey-dummy-package.nuspec rename to tests/chocolatey-tests/commands/testpackages/chocolatey-dummy-package/1.0.0/chocolatey-dummy-package.nuspec diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/installpackage.nuspec b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/installpackage.nuspec similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/installpackage.nuspec rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/installpackage.nuspec diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/Casemismatch.exe.ignore b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/Casemismatch.exe.ignore similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/Casemismatch.exe.ignore rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/Casemismatch.exe.ignore diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/casemismatch.exe b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/casemismatch.exe similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/casemismatch.exe rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/casemismatch.exe diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyBeforeModify.ps1 b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyBeforeModify.ps1 similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyBeforeModify.ps1 rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyBeforeModify.ps1 diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyinstall.ps1 b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyinstall.ps1 similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyinstall.ps1 rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyinstall.ps1 diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyuninstall.ps1 b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyuninstall.ps1 similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/chocolateyuninstall.ps1 rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/chocolateyuninstall.ps1 diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/console.exe b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/console.exe similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/console.exe rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/console.exe diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/graphical.exe b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/graphical.exe similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/graphical.exe rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/graphical.exe diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/graphical.exe.gui b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/graphical.exe.gui similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/graphical.exe.gui rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/graphical.exe.gui diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/not.installed.exe b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/not.installed.exe similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/not.installed.exe rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/not.installed.exe diff --git a/tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/not.installed.exe.ignore b/tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/not.installed.exe.ignore similarity index 100% rename from tests/chocolatey-tests/testpackages/installpackage/1.0.0/tools/not.installed.exe.ignore rename to tests/chocolatey-tests/commands/testpackages/installpackage/1.0.0/tools/not.installed.exe.ignore diff --git a/tests/chocolatey-tests/testpackages/too-long-description/1.0.0/too-long-description.nuspec b/tests/chocolatey-tests/commands/testpackages/too-long-description/1.0.0/too-long-description.nuspec similarity index 100% rename from tests/chocolatey-tests/testpackages/too-long-description/1.0.0/too-long-description.nuspec rename to tests/chocolatey-tests/commands/testpackages/too-long-description/1.0.0/too-long-description.nuspec diff --git a/tests/chocolatey-tests/testpackages/too-long-title/1.0.0/too-long-title.nuspec b/tests/chocolatey-tests/commands/testpackages/too-long-title/1.0.0/too-long-title.nuspec similarity index 100% rename from tests/chocolatey-tests/testpackages/too-long-title/1.0.0/too-long-title.nuspec rename to tests/chocolatey-tests/commands/testpackages/too-long-title/1.0.0/too-long-title.nuspec diff --git a/tests/chocolatey-tests/testpackages/zip-log-disable-test/tools/chocolateyinstall.ps1 b/tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/tools/chocolateyinstall.ps1 similarity index 100% rename from tests/chocolatey-tests/testpackages/zip-log-disable-test/tools/chocolateyinstall.ps1 rename to tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/tools/chocolateyinstall.ps1 diff --git a/tests/chocolatey-tests/testpackages/zip-log-disable-test/tools/zip-log-disable-test.zip b/tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/tools/zip-log-disable-test.zip similarity index 100% rename from tests/chocolatey-tests/testpackages/zip-log-disable-test/tools/zip-log-disable-test.zip rename to tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/tools/zip-log-disable-test.zip diff --git a/tests/chocolatey-tests/testpackages/zip-log-disable-test/zip-log-disable-test.nuspec b/tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/zip-log-disable-test.nuspec similarity index 100% rename from tests/chocolatey-tests/testpackages/zip-log-disable-test/zip-log-disable-test.nuspec rename to tests/chocolatey-tests/commands/testpackages/zip-log-disable-test/zip-log-disable-test.nuspec diff --git a/tests/chocolatey-tests/features/Hooks.Tests.ps1 b/tests/chocolatey-tests/features/Hooks.Tests.ps1 new file mode 100644 index 0000000000..74d7ce5292 --- /dev/null +++ b/tests/chocolatey-tests/features/Hooks.Tests.ps1 @@ -0,0 +1,93 @@ +Import-Module helpers/common-helpers + +Describe "choco hooks tests" -Tag Chocolatey, HooksFeature { + BeforeDiscovery { + $Flags = @( + @{ Flag = '' ; RunsHooks = $true ; Command = 'install' ; ExitCode = 0 } + @{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'install' ; ExitCode = 0 } + @{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'install' ; ExitCode = 0 } + + @{ Flag = '' ; RunsHooks = $true ; Command = 'uninstall' ; ExitCode = 0 } + @{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'uninstall' ; ExitCode = 0 } + @{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'uninstall' ; ExitCode = 0 } + + @{ Flag = '' ; RunsHooks = $true ; Command = 'upgrade' ; ExitCode = -1 } + @{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'upgrade' ; ExitCode = 0 } + @{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'upgrade' ; ExitCode = -1 } + + ) + } + 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 ' hooks with 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 expected value ()" { + $Output.ExitCode | Should -Be $ExitCode -Because $Output.String + } + + It "Should execute hooks ()" { + $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 + } + } +} diff --git a/tests/chocolatey-tests/PythonSource.Tests.ps1 b/tests/chocolatey-tests/features/PythonSource.Tests.ps1 similarity index 100% rename from tests/chocolatey-tests/PythonSource.Tests.ps1 rename to tests/chocolatey-tests/features/PythonSource.Tests.ps1