[chef] Re: Re: Testing and chef best practices


Chronological Thread 
  • From: Lamont Granquist < >
  • To:
  • Cc: Yoshi Spendiff < >
  • Subject: [chef] Re: Re: Testing and chef best practices
  • Date: Tue, 16 Jun 2015 19:10:53 -0700

If you are intending this as a library cookbook for public reuse its better to follow the pattern in the new mysql and httpd cookbooks.

Don't use attributes or recipes at all and instead export resources and providers.  Those kinds of cookbooks shouldn't have anything in the attributes directory or anything in the recipes directory.

And if you're not familiar with ChefSpec, Rspec, Chef architecture and unit testing then ChefSpec can be a bit much conceptually at first.  People who pick that up often start trying to write tests to test Chef's behavior instead of just testing that the resource collection is getting constructed correctly (and if you write LWRPs then you immediately start trying to test LWRPs with ChefSpec which gets even more interesting).  Doing integration tests with serverspec is a lot more natural since you're spinning up a virt and really converging chef against it and then testing fairly logical assertions like "must be listening on port 80".  The problem with integration tests is that they're much slower and ChefSpec gives you the ability to test cross platform code without spinning up any virts at all.  I'd start learning about testing chef recipes with TK+serverspec (or BATS) first.

On 06/16/2015 08:06 AM, Yoshi Spendiff wrote:
" type="cite">
1. Parameterise it if it's something that would need changing. If it's a service for something specific and that service usually has a well known name then don't parameterise it
2. If you use parameters then set them as attributes in an attribute file in your cookbook, i.e.
     default['mycookbook']['service_name'] = 'myservice'
     default['mycookbook']['service_port'] = 1234
3. If this is a cookbook that you intend to release to the community then I would write both unit and integration tests. It's a lot quicker to run a chefspec suite (especially if you use caching instead of let) than full integration tests, so you can run those while you're developing to quickly see if you've introduced a problem and then move up to integration tests once those pass

On Mon, Jun 15, 2015 at 8:22 PM, Sean Farrow < " target="_blank"> > wrote:

Hi,

 

I am writing a recipe that cretes a windows service. Is it better to have a hard-coded service name or parameterize this in some way? I the latter, what method is better, databags or is ther something else?

Also should I write a unit test using ChefSpec for this or is just an integration test sufficient?

What are people’s testing preferences around uses of third-party cookbooks?

Kind regards

Sean.




--
Yoshi Spendiff
Ops Engineer
Indochino
Mobile: +1 778 952 2025




Archive powered by MHonArc 2.6.16.

§