Create Puppet module test case less than 5 minutes
• Niko Kiuru
In this post, I'll tell you how to create Puppet module test cases. If you are newbie with Puppet, I recommend you begin by my another post Hello Puppet!.
My using operating system is Xubuntu 14.04 LTS.
As every project begin in Hello world, by the same way our project begin in Hello Git!
Create directory structure:
Create init.pp in manifests:
And write bottom lines in file:
Run our git module:
And now git should be installed to our system.
Create test case
Is time to go on and let make our first test case. In web, I have seen many different variations to make this part of post. But I like to make things easiest way as possible, so I'll show you how to make this part as simplest I know so far.
Goto git module root:
Write necessary gems in Gemfile.
And bundle install gems:
Run command rspec-puppet-init, and we got full nicely generated spec directory structure:
Rspec-puppet for some reason miss require puppetlabs_spec_helper. We add it into bottom of file:
Write some test case. That is the way, how we verify and be sure that our git class contain package git.
And now we're able to run our test case. Because we are using Gemfile, is very important to run rake spec with bundle! If you're not using bundle, you're not even use Gemfile, so you're not using your specified gems versions! It isn't good practice, so use bundle: