This is a quick post to introduce what I’m starting on testing with ChefSpec. This is from Opscode’s Java cookbook. While the recipe tested is really trivial, it actually has some nuances that require detailed testing.
First off, the whole thing is in
this gist. I’m going to
break it down into sections below. The file is
in the java cookbook (not committed/pushed yet).
The chefspec gem is where all the magic comes from. You can read about
ChefSpec on its home page. You’ll
need to install the gem, and from there, run
rspec to run the tests.
Next, we’re going to describe the default recipe. We’re using the
regular rspec “let” block to set up the runner to converge the recipe.
Then, because we know/assume that the openjdk recipe is the default,
we can say that this chef run should include the
1 2 3 4 5
Next, this cookbook supports Windows. However, we have to set up the runner with the correct platform and version (this comes from fauxhai), and then set attributes that are required for it to work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Next are the contexts for other install flavors. The default recipe will include the right recipe based on the flavor, which is set by an attribute. So we set up an rspec context for each recipe, then set the install flavor attribute, and test that the right recipe was included.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Finally, a recent addition to this cookbook is support for
IBM’s Java. In addition
to setting the install flavor, we must set the URL where the IBM Java
package is (see the README in the commit linked in that ticket for
detail), and we can see that the
ibm recipe is in fact included.
1 2 3 4 5 6 7 8 9 10 11 12
This is just the start of the testing for this cookbook. We’ll need to test each individual recipe. However as I’ve not written that code yet, I don’t have examples. Stay tuned!