Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#798, #2787, #1185) Add or update tests for side by side installs, pin during install/upgrade, hook scripts #2823

Merged
merged 6 commits into from
Sep 26, 2022

Conversation

corbob
Copy link
Member

@corbob corbob commented Sep 21, 2022

Description Of Changes

Add or update tests for side by side installations being deprecated, pin package during install and upgrade, and hook scripts.

Motivation and Context

  • The tests for side by side installation deprecation inadvertently missed restoring the snapshot, this does that restore so the tests past in Test Kitchen.
  • The ability to pin a package during installation and upgrade was recently added. This adds tests for that to ensure it's pinning packages as expected.
  • The ability to have pre and post action hooks was added. This adds end to end testing to ensure they're working as expected.

Testing

  1. Pulled down the package build by Team City
  2. Used that package in Test Kitchen to run these tests.
  3. Manually ran some choco install commands to ensure that there are no warnings about $env:ChocolateyInstall/hooks not being found.

Change Types Made

  • Bug fix (non-breaking change)
  • Feature / Enhancement (non-breaking change)
  • Breaking change (fix or feature that could cause existing functionality to change)
  • PowerShell code changes.

Related Issue

Related to:

Change Checklist

  • Requires a change to the documentation
  • Documentation has been updated
  • Tests to cover my changes, have been added
  • All new and existing tests passed.
  • PowerShell v2 compatibility checked.

@coveralls
Copy link

coveralls commented Sep 21, 2022

Coverage Status

Coverage decreased (-0.002%) to 27.578% when pulling 794bf67 on corbob:a798-pin-package into d08d1f6 on chocolatey:develop.

@corbob corbob changed the title TBD (#798, #2787, #1185) Add or update tests for side by side installs, pin during install/upgrade, hook scripts Sep 21, 2022
@corbob corbob marked this pull request as ready for review September 21, 2022 16:34
@corbob corbob requested a review from AdmiringWorm September 21, 2022 16:34
@choco-bot
Copy link

Task linked: ENGTASKS-1480 Chocolatey CLI

tests/chocolatey-tests/Hooks.Tests.ps1 Outdated Show resolved Hide resolved
tests/chocolatey-tests/Hooks.Tests.ps1 Outdated Show resolved Hide resolved
tests/chocolatey-tests/Hooks.Tests.ps1 Outdated Show resolved Hide resolved
@corbob corbob requested a review from AdmiringWorm September 23, 2022 19:55
@corbob corbob force-pushed the a798-pin-package branch 2 times, most recently from d26f68d to 60aefc7 Compare September 24, 2022 16:23
Copy link
Member

@AdmiringWorm AdmiringWorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran the tests you had changed, and a few of them are currently failing in test kitchen.

Would need to fix up these tests before we can merge the changes into the repository.

        Context uninstall hooks with flag: 
          [-] Exits with expected value (-1) 421ms (418ms|4ms)
           Expected -1, because Chocolatey v1.2.0-PullReques-20220924-ff3e5fda
           Uninstalling the following packages:
           upgradepackage
           pre-beforemodify-all.ps1 hook ran for upgradepackage 1.1.0
           pre-beforemodify-upgradepackage.ps1 hook ran for upgradepackage 1.1.0
           upgradepackage 1.1.0 Before Modification
           post-beforemodify-all.ps1 hook ran for upgradepackage 1.1.0
           post-beforemodify-upgradepackage.ps1 hook ran for upgradepackage 1.1.0
           upgradepackage v1.1.0
           pre-uninstall-all.ps1 hook ran for upgradepackage 1.1.0
           pre-uninstall-upgradepackage.ps1 hook ran for upgradepackage 1.1.0
           upgradepackage 1.1.0 Uninstalled
           post-uninstall-all.ps1 hook ran for upgradepackage 1.1.0
           post-uninstall-upgradepackage.ps1 hook ran for upgradepackage 1.1.0
            Skipping auto uninstaller - No registry snapshot.
           [NuGet] Skipping 'upgradepackage\tools\console.exe.config' it was modified.
            upgradepackage has been successfully uninstalled.
           Chocolatey uninstalled 1/1 packages. 
            See the log for details (C:\Users\Administrator\AppData\Local\Temp\ChocolateyTests\snapshots\8f2b5c8e-e96a-4435-8cdf-06b9b3ef67ce\install\logs\chocolatey.log)., but got 0.
           at $Output.ExitCode | Should -Be $ExitCode -Because $Output.String, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
           at <ScriptBlock>, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
          [+] Should execute hooks (True) 14ms (13ms|1ms)
        Context uninstall hooks with flag: --skip-powershell
          [-] Exits with expected value (-1) 10ms (7ms|2ms)
           Expected -1, because Chocolatey v1.2.0-PullReques-20220924-ff3e5fda
           Uninstalling the following packages:
           upgradepackage
           upgradepackage v1.1.0
            Skipping auto uninstaller - No registry snapshot.
           [NuGet] Skipping 'upgradepackage\tools\console.exe.config' it was modified.
            upgradepackage has been successfully uninstalled.
           Chocolatey uninstalled 1/1 packages. 
            See the log for details (C:\Users\Administrator\AppData\Local\Temp\ChocolateyTests\snapshots\c39395d6-cebd-4e88-91fa-0e46af87270b\install\logs\chocolatey.log)., but got 0.
           at $Output.ExitCode | Should -Be $ExitCode -Because $Output.String, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
           at <ScriptBlock>, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
          [+] Should execute hooks (False) 9ms (8ms|1ms)
        Context uninstall hooks with flag: --skip-hooks
          [-] Exits with expected value (-1) 8ms (5ms|2ms)
           Expected -1, because Chocolatey v1.2.0-PullReques-20220924-ff3e5fda
           Uninstalling the following packages:
           upgradepackage
           upgradepackage 1.1.0 Before Modification
           upgradepackage v1.1.0
           upgradepackage 1.1.0 Uninstalled
            Skipping auto uninstaller - No registry snapshot.
           [NuGet] Skipping 'upgradepackage\tools\console.exe.config' it was modified.
            upgradepackage has been successfully uninstalled.
           Chocolatey uninstalled 1/1 packages. 
            See the log for details (C:\Users\Administrator\AppData\Local\Temp\ChocolateyTests\snapshots\c25ff219-d293-47e3-bbfc-f1464bf3af55\install\logs\chocolatey.log)., but got 0.
           at $Output.ExitCode | Should -Be $ExitCode -Because $Output.String, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
           at <ScriptBlock>, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
          [+] Should execute hooks (False) 14ms (13ms|1ms)
        Context upgrade hooks with flag: 
          [+] Exits with expected value (-1) 9ms (3ms|6ms)
          [+] Should execute hooks (True) 13ms (12ms|1ms)
        Context upgrade hooks with flag: --skip-powershell
          [-] Exits with expected value (-1) 6ms (4ms|2ms)
           Expected -1, because Chocolatey v1.2.0-PullReques-20220924-ff3e5fda
           Upgrading the following packages:
           upgradepackage
           By upgrading, you accept licenses for the packages.
           You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source(s).
           [NuGet] Skipping 'upgradepackage\tools\console.exe.config' it was modified.
           upgradepackage v1.1.0
           upgradepackage package files upgrade completed. Performing other installation steps.
           Transforming 'console.exe.config' with the data from 'console.exe.config.install.xdt'
            ShimGen has successfully created a shim for console.exe
            ShimGen has successfully created a gui shim for graphical.exe
            The upgrade of upgradepackage was successful.
             Software installed to 'C:\Users\Administrator\AppData\Local\Temp\ChocolateyTests\snapshots\3ee22d6b-ce0d-41c3-9d78-926a1a7b2312\install\lib\upgradepackage'
           Chocolatey upgraded 1/1 packages. 
            See the log for details (C:\Users\Administrator\AppData\Local\Temp\ChocolateyTests\snapshots\3ee22d6b-ce0d-41c3-9d78-926a1a7b2312\install\logs\chocolatey.log)., but got 0.
           at $Output.ExitCode | Should -Be $ExitCode -Because $Output.String, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
           at <ScriptBlock>, C:\Users\vagrant\AppData\Local\Temp\verifier\suites\chocolatey-tests\features\Hooks.Tests.ps1:51
          [+] Should execute hooks (False) 7ms (6ms|1ms)

The info tests enable a proxy that prevents the side by side tests from
actually working correctly. This restores the Snapshot so we have a
fresh Chocolatey installation to test against.
Add tests that we are pinning packages when during upgrade and install
when done with the `--pin` parameter.
Add tests that hook scripts execute in scenarios where they're expected
to run.
Move the command tests into a new commands directory, with features in a
new features directory. This should make it easier and clearer which
tests are specific to what aspects of Chocolatey.
With the upgrade package used in the tests, it currently exits with -1
even though it is successful. Instead of blindly accepting 0 and -1 for
all the tests, be explicit about which one we expect so we can catch
changes to this exit code.
@corbob
Copy link
Member Author

corbob commented Sep 26, 2022

I've fixed up those exit codes @AdmiringWorm so they should all pass now. It seems I forgot which packages were being used where and when to expect 0 and -1 😅

Copy link
Member

@AdmiringWorm AdmiringWorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AdmiringWorm AdmiringWorm merged commit 63c8cbd into chocolatey:develop Sep 26, 2022
@AdmiringWorm
Copy link
Member

@corbob thank you for getting this added and fixed up 👍

@corbob corbob deleted the a798-pin-package branch September 26, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants