How to run the test suite Edit

Published on Oct 20, 2021.

The testing and development tools have a bunch of dependencies, all managed by bundler. By default the tests use the latest version of Puppet. If you want a specific version of Puppet, you must set an environment variable such as:

export PUPPET_VERSION="~> 8.8.1"

Running the tests in a local ruby environment

Installing requirements

You can install all needed gems for spec tests into the modules directory by running:

bundle config set --local path 'vendor'
bundle config set --local without 'development system_tests release'
BUNDLE_JOBS="$(nproc)" bundle install

If you also want to run acceptance tests, don’t exclude the system_tests group.

If you don’t know if you need to install or update gems, you can just add bundle update && bundle clean as an additional command.

Vox Pupuli helpers

Check out the following page if you want to add a test suite to your module or want to learn more about the Vox Pupuli test helpers:

Linting

Vox Pupuli uses puppet-lint for better code quality. To run it:

bundle exec rake lint

To automatically fix puppet-lint issues you can use:

bundle exec rake lint_fix

Aso run some RuboCop tests against it:

bundle exec rake rubocop

RuboCop also supports save autofixing:

bundle exec rake rubocop:autocorrect

And another autofix option that can fix more, but might break your code:

bundle exec rake rubocop:autocorrect_all

Unit tests

The unit test suite covers most of the code, as mentioned above please add tests if you’re adding new functionality. If you’ve not used rspec-puppet before then feel free to ask about how best to test your new feature.

To run the linter, the syntax checker and the unit tests:

bundle exec rake test

Detailed sub tasks

bundle exec rake spec

If you have multiple cpu cores available we suggest using the following command:

bundle exec rake parallel_spec

Single test file could be run by:

bundle exec rspec spec/classes/myclass_spec.rb
bundle exec rake spec SPEC=spec/classes/myclass_spec.rb

To limit test execution to a certain os or os release you can set the environment variable SPEC_FACTS_OS.

export SPEC_FACTS_OS=centos
export SPEC_FACTS_OS=centos-7

Acceptance tests

The unit tests just check the code runs, not that it does exactly what we want on a real machine. For that we’re using beaker.

This fires up a new virtual machine or container and runs a series of simple tests against it after applying the module. You can run this on your own with:

BEAKER_SETFILE=centos9-64 bundle exec rake beaker

How to run the acceptance tests is described more in detail on this page: voxpupuli-acceptance

REFERENCE.md update

If REFERENCE.md is now out of date you can fix it with:

bundle exec rake strings:generate:reference

Running the tests in the VoxBox container

Struggling with Ruby installations or dependency issues? VoxBox simplifies your workflow by providing a ready-to-use container with all the Ruby tools you need. To guarantee a consistent rake environment, use -f /Rakefile to explicitly specify your Rakefile, rather than relying on potentially outdated versions in a repository. Learn more in the project’s README.

Installation

podman pull ghcr.io/voxpupuli/voxbox:8

Linting

cd my/module
podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile lint
podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile lint_fix

# lint with all lint plugins enabled, puppetlabs-spec_helper deactivates some of them
podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile voxpupuli:custom:lint_all

Rubocop

podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile rubocop
podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile rubocop:autocorrect

Unit tests

podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile spec
podman run -it --rm -e "SPEC_FACTS_OS=centos" -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile spec
podman run -it --rm -e "SPEC=spec/classes/myclass_spec.rb" -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile spec

REFERENCE.md update

podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile strings:generate:reference

Puppetfile

podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile r10k:syntax
podman run -it --rm -v $PWD:/repo:Z ghcr.io/voxpupuli/voxbox:8 -f /Rakefile r10k:dependencies