Acceptance testing for Puppet is done using Beaker. This product was developed in house at Puppet labs and grew out of the old rspec-system tool. Documentation for Beaker is a little patchy but getting rapidly better.
Beaker can use loads of different cloud and virtualization infrastructures to create SUTs (System Under Test).
Puppet Acceptance Testing With Beaker
Test-driven development can bring a number of benefits. An approach where you write tests first makes you think about what you need to develop. Subsequent refactoring generally leads to designs that emerge in the code with high levels of test coverage.
Beaker can manage the temporary creation of a SUT via a hypervisor. The Puppet module under test is installed and then the tests are executed.
Beaker can be installed via a Gemfile
Use bundler to install the gems
Typically Beaker acceptance tests are held in a spec/acceptance subdirectory.
A spec/acceptance/nodesets subdirectory defines the machines that we want to test against. Nodesets are yaml files that define the machine’s name, location and platform. The hypervisor type is also specified. Examples for Vagrant can be found here.
The spec_helper_acceptance.rb file provides the basic configuration. The module under test is copied on to each host. UNSUPPORTED_PLATFORMS provides an easy way to de-scope tests for a particular platform.
The acceptance tests describe the expected behaviour and state of the SUT and are written in RSpec. In this example, a test context is defined for user (and group) creation.
This test context applies the manifest, expects it to execute without errors and then validates that a user is created in the correct group.
Tests can be run with
Beaker will initially use the specified hypervisor to bring up a SUT.
Puppet will then be installed and the acceptance tests within spec/acceptance will be performed.
Generally, each test applies manifests within the module for a particular context.
The tests are then performed. Beaker resolves them to an underlying operating system command in order to validate the assertion
The hypervisor will then shutdown and destroy the SUT. Beaker reports on the results when all the tests have completed.