A testing environment setup similar to the package-verifier for testing packages. Over time this will add more Windows platforms for testing.
When creating packages or testing other parts of Chocolatey, this environment provides a good base for an independent testing minus any dependencies you may already have installed. It also allows you to completely destroy an environment and then just tear it down without worry about messing up something on your own system.
When creating packages, please review https://github.com/chocolatey/choco/wiki/CreatePackages
You need a computer with:
To get started, ensure you have the following installed:
NOTE: If you decide to run with version 1.8.1 of Vagrant, you are going to need to set the VAGRANT_SERVER_URL
environment variable as described in this forum post, otherwise, you will get an HTTP 404 error when attempting to download the base vagrant box used here.
NOTE: The CDN for packages on https://chocolatey.org will only update every 30 minutes. This means if you just pushed an updated version, within 30 minutes from the last access time of the package it will be updated. This is why the validator and verifier wait for 31 minutes prior to testing a package.
PowerShell.exe
/cmd.exe
on Windows, bash
everywhere else) and navigate to the root folder of the repository. You know you are in the right place when you do a dir
or ls
and Vagrantfile
is in your path.
PowerShell.exe
or cmd.exe
. Please do not file issues stating it doesn't work.vagrant up
to prepare the machine for testing.
Vagrantfile
. You can find the downloaded box in the ~/.vagrant.d
or c:\users\username\.vagrant.d
folder.vagrant snapshot save good
. This takes a snapshot of the VM using the built-in snapshot functionality. This means that after testing packages, the VM can be returned to this known "good" state.For testing a package, you have two avenues. For a locally built package, you can drop the package into the packages
folder in the root of the cloned repository - it is shared with the box as C:\packages
, so you can run a command on the box or with the inline provisioner (recommended as it is a closer match to the verifier) using --source c:\packages
as an argument for installation. If you are trying to reproduce/investigate a problem with a package already up on the website, you can use --version number
with your install arguments and that will let you install a package that is not listed (in most cases not yet approved).
# THIS IS WHAT YOU CHANGE
. Uncomment and edit the line which best meets the current situation that you are testing.vagrant provision
.When you need to investigate making changes and rerunning the tests, remember that we took a snapshot of the vagrant machine (the virtual machine), so we can rollback to the earlier state each time and move forward with testing changes without the possibility of lingering artifacts. This is why we are using the vagrant snapshot
command, it allows us to take a snapshot and then revert the virtual machine back to the previous state.
When you are ready to reset to the state just before installing:
vagrant snapshot restore good --no-provision
NOTE: At any time you can:
vagrant suspend
, vagrant halt
vagrant destroy
When bringing up your testing environment Vagrant may report that the box being used is out of date. You can also manually check to see if a newer box is available using the vagrant box outdated
command.
To upgrade the vagrant box used by your testing environment:
vagrant box update
vagrant destroy
Vagrantfile
back to it's default, i.e. there should not be any uncommented lines from testing packages
vagrant up
to prepare the testing environment with the new boxvagrant snapshot save good
If you don't want to use the latest available Vagrant box, you can select a specific box version or otherwise constrain the valid versions used in your testing environment. To do so, edit the Vagrantfile
and uncomment the config.vm.box_version
line.
By default this will set the desired box version to "2.0.0" which is the last Windows Server 2012 R2 version available.
You can adjust this setting to meet your needs, for more information on the options available see the documentation on Version Constraints.
For more information on vagrant commands, see the Vagrant Docs
[!CAUTION] It is recommended to favor running the Chocolatey Test Environment under VirtualBox.
Hyper-V support is intended to lower the barrier to entry for those using Windows features which force the usage of Hyper-V, such as the Windows Subsystem for Linux (WSL 2), Windows Sandbox, Device Guard, and Credential Guard.
Please be sure that you're aware of the limitations of using the Vagrant Hyper-V provider.
[!NOTE] The Hyper-V role requires Windows 10 or 11 Enterprise, Pro, or Education. It cannot be installed on Home editions of Windows.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All
.vagrant up
command with vagrant up --provider=hyperv
.
There are a couple of difference between the Package Verifier service and this environment.
The verifier is run without the GUI - meaning it is run in a headless state. There is no box to interact with.
Package Verifier only runs against Windows Server 2019, currently.
Package Verifier times out on waiting for a command after 12 minutes.
Synced folders are different - Package Verifier syncs the .chocolatey
folder to gather the package information files.
Specific VM settings are different (for performance):
v.gui = false
v.customize ["modifyvm", :id, "--memory", "6144"]
v.customize ["modifyvm", :id, "--cpus", "4"]
v.customize ["modifyvm", :id, "--clipboard", "disabled"]
v.customize ["modifyvm", :id, "--draganddrop", "disabled"]
Run vagrant init
to create a new Vagrant environment. Or, get an ID of a target machine from vagrant global-status
to run this command on. A final option is to change to a directory with a Vagrantfile and to try again." - please ensure you are on the correct working directory (where this ReadMe and Vagrantfile
is) of this repo and try again.
Edit Vagrantfile and find the # Port forward WinRM / RDP
section. uncomment #, host_ip: "127.0.0.1"
(remove the #
). Run vagrant up
again.
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true , host_ip: "127.0.0.1"