Cookbook recipe template development and unit testing?


#1

Good day!
I’ve been searching about and can’t find the answers I seek… web searches
for cookbook recipe testing seem to be mostly, um, food-related :]

I’m in the process of replacing my home-brew templating system with chef
server and recipes with templates.

In my system, I can just run "perl templater.pl <template_file> – " and it will take in the custom args and feed them back
to the template, spitting out the result of the template to stdout. It is
great for testing small template file changes before pushing them out to
the server.

How can I do this with chef? There is a defaults.rb for all of the default
attribute values, which should be enough to generate a template… is there
a way to say "chef-solo cookbooktest /path/to/mycookbook --outputdir /tmp"
or something to that effect?

Thanks,
-Jesse Campbell


#2

No responses here, and there didn’t appear to be any test framework in
place, so I just wrote a simple ruby script that can be updated and tuned
on a per-template basis…

I will likely eventually tune it a bit to parse a recipe file, rather than
being hard-coded with recipe-specific context and template file name, but
this works for me for now.
In case anyone else might find it useful, it can be found here, tuned for
the sudoers.erb template:

-Jesse

On Fri, Jan 6, 2012 at 10:44, Jesse Campbell hikeit@gmail.com wrote:

Good day!
I’ve been searching about and can’t find the answers I seek… web
searches for cookbook recipe testing seem to be mostly, um, food-related :]

I’m in the process of replacing my home-brew templating system with chef
server and recipes with templates.

In my system, I can just run “perl templater.pl <template_file> –
” and it will take in the custom args and feed
them back to the template, spitting out the result of the template to
stdout. It is great for testing small template file changes before pushing
them out to the server.

How can I do this with chef? There is a defaults.rb for all of the default
attribute values, which should be enough to generate a template… is there
a way to say "chef-solo cookbooktest /path/to/mycookbook --outputdir /tmp"
or something to that effect?

Thanks,
-Jesse Campbell