Testing advice

Hello,

I am in the process of creating a cookbook that uses other cookbooks/recipe’s.
What RSpec/ServerSpec tests would people write in this situation?
Any advice appreciated.
Kind regards
Sean.

we use chefspec for unit testing, and raw LXC + rsepc (with ruby telnet,
blender etc based matchers) for integration testing. the whole thing is
CI/CDed under GoCD. We had blogged about it in past[1]. Its pretty
backdated now, our spec helper modules have changed a lot after blender
releases, to support multi node testing (for zk. cass clusters) as well as
after GoCD became opensource. You can check the GoatOS project which is
takes similar approach for testing chef along side cookbook against every
chef master changes.

I have avoided using serverspec for its limitations related to single node
specs, as well as weird library styles and issue tracking. also during
functional tests i tend to test the outcome of a chef role/cookbook rather
than individual resources, like zookeeper functional tests will do a telnet
against zk hosts’ port 2171 and check for stats. Or for mysql its ability
to upload fixture data.

hth
ranjib
[1]https://www.pagerduty.com/blog/chef-testing-pagerduty/

On Wed, Sep 30, 2015 at 11:48 AM, Sean Farrow sean.farrow@seanfarrow.co.uk
wrote:

Hello,

I am in the process of creating a cookbook that uses other
cookbooks/recipe’s.

What RSpec/ServerSpec tests would people write in this situation?

Any advice appreciated.

Kind regards

Sean.

For the Rspec tests I’m assuming you mean ChefSpec, in which case you only
cover the code you write in your own cookbook. If you use the berkshelf
plug-in then it by defaults filters the checks against code only in your
cookbook. Remember to turn on code coverage resports.

These two posts cover it well:


For the ServerSpec tests you check that the end result scenario of all of
your cookbook code worked, e.g. so certain services are started, certain
files are created as the end result of a run (not files deployed by chef),
certain ports are listening and so on. Avoid duplicating tests that the
upstream cookbooks already implement and there’s little point duplicating
tests implemented by ChefSpec unless you’re super duper paranoid about
something working.

On 30 September 2015 at 11:48, Sean Farrow sean.farrow@seanfarrow.co.uk
wrote:

Hello,

I am in the process of creating a cookbook that uses other
cookbooks/recipe’s.

What RSpec/ServerSpec tests would people write in this situation?

Any advice appreciated.

Kind regards

Sean.

By the way: has anybody from this list actually tried infrataster or
leibniz for multi-node integration testing?

That’s one of the things on my list I always wanted to check out but really
never came to it yet…

​[0]​ http://infrataster.net/
​[1] https://github.com/Atalanta/leibniz​

On Wed, Sep 30, 2015 at 9:36 PM, Yoshi Spendiff yoshi@spendiff.net wrote:

For the Rspec tests I’m assuming you mean ChefSpec, in which case you only
cover the code you write in your own cookbook. If you use the berkshelf
plug-in then it by defaults filters the checks against code only in your
cookbook. Remember to turn on code coverage resports.

These two posts cover it well:
https://sethvargo.com/unit-testing-chef-cookbooks/
https://sethvargo.com/chef-recipe-code-coverage/

For the ServerSpec tests you check that the end result scenario of all of
your cookbook code worked, e.g. so certain services are started, certain
files are created as the end result of a run (not files deployed by chef),
certain ports are listening and so on. Avoid duplicating tests that the
upstream cookbooks already implement and there’s little point duplicating
tests implemented by ChefSpec unless you’re super duper paranoid about
something working.

On 30 September 2015 at 11:48, Sean Farrow sean.farrow@seanfarrow.co.uk
wrote:

Hello,

I am in the process of creating a cookbook that uses other
cookbooks/recipe’s.

What RSpec/ServerSpec tests would people write in this situation?

Any advice appreciated.

Kind regards

Sean.

Sorry about the super slow response. I think I got unsubscribed to a list or two.

I would check if the upstream cookbook already has tests and make sure not to duplicate them (which will save you a lot of work).

You would want to at least test for your include_recipe statements if you are including recipes, otherwise if you are using cookbooks that only expose resources you can just test your declared resources like standard Chef resources in ServerSpec (so long as that cookbook includes a matchers.rb library)