The following example walks you through enabling Litmus testing in a module.
The process involves editing or adding code to the following files:
Gemfile
Rakefile
.fixtures.yml
filespec_helper_acceptance.rb
filespec_helper_acceptance_local.rb
fileThis guide assumes your module is compatible with Puppet Development Kit (PDK),
meaning it was either created with pdk new module
or has been converted to use PDK using the pdk convert
command.
To verify that your module is compatible with PDK, look in the modules metadata.json
file and see whether there is an entry that states the PDK version.
It will look something like "pdk-version": "1.18.0"
.
The PDK ships litmus as an experimental component.
To enable it, follow the steps below.
Inside the root directory of your module, add the following entries to the .fixtures.yml
:
---
fixtures:
repositories:
facts: 'https://github.com/puppetlabs/puppetlabs-facts.git'
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
provision: 'https://github.com/puppetlabs/provision.git'
spec/spec_helper_acceptance.rb
fileInside the spec
folder of the module, create a spec_helper_acceptance.rb
file with the following contents:
# frozen_string_literal: true
require 'puppet_litmus'
PuppetLitmus.configure!
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
This file will later become managed by the PDK. For local changes, see the next step.
spec/spec_helper_acceptance_local.rb
fileOptional: For module-specific methods to be used during acceptance testing, create a spec/spec_helper_acceptance_local.rb
file. This will be loaded at the start of each test run. If you need to use any of the Litmus methods in this file, include Litmus as a singleton class:
# frozen_string_literal: true
require 'singleton'
class Helper
include Singleton
include PuppetLitmus
end
def some_helper_method
Helper.instance.bolt_run_script('path/to/file')
end
spec/acceptance
You can find litmus test examples on their own page.