PuppetUnitTests
Write Puppet unit tests in YAML.
Describe environment (facts, Hiera data, etc.) and expected result (error, resource in catalog, or resource not in catalog). Use stubs that may be shared with other modules.
Installation
Install this gem on your development and CI/CD hosts:
/opt/puppetlabs/puppet/bin/gem install puppet-unit-tests
Usage
Create a "test" directory under your module root. Create subdir "class" for classes, "define" for defined types. Create YAML files inside this directories with usecases and expected results. Files must be named exactly as the Puppet object they should test. For example, usecases for a class "foo::bar" should be stored in file "tests/class/foo::bar.yaml".
A minimal file for a class:
---
usecases:
'it compiles':
Add these lines to your Rakefile:
require 'puppet_unit_tests/rake_task'
PuppetUnitTests::RakeTask.new
TODO: how to customize task name
Run tests with:
rake test
TODO: example CI/CD with Laminar?
Development
TODO: review these instructions, correct and complete them.
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://codeberg.org/arlol/puppet-unit-tests. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Code of Conduct
TODO: review automatic bundler code-of-conduct more thoroughly.
Everyone interacting in the Puppetunittests project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.