Use of chef-zero in unit testing

I am writing rspec tests for tools that interact with the chef, i.e. pushing of new cookbooks to the chef-server, creating Chef::Node objects from asset-tracking system.

I was thinking of firing up a chef-zero instance to used as the backend for these tests. A couple issues I see:

  1. chef-zero requires a port to be specified. Since there may be multiple tests running simultaneously, need to use different ports. I suppose I could iterate over a range of ports and use that one if it succeeds.

  2. Teardown. I suppose an after(:all) clause to do a zero.stop would do the trick.

Before I start, has anyone else gone down this path?

Thanks.

Joe

Hi Joe,

Have you tried using test kitchen with the chef-zero provider? That pretty much handles this whole test harness automagically, including the port numbers on multiple instances, spin-up/down, etc.

Eric

On March 14, 2014 at 12:17:40 PM, Joe Nuspl (nuspl@nvwls.com) wrote:

I am writing rspec tests for tools that interact with the chef, i.e. pushing of new cookbooks to the chef-server, creating Chef::Node objects from asset-tracking system.

I was thinking of firing up a chef-zero instance to used as the backend for these tests. A couple issues I see:

  1. chef-zero requires a port to be specified. Since there may be multiple tests running simultaneously, need to use different ports. I suppose I could iterate over a range of ports and use that one if it succeeds.

  2. Teardown. I suppose an after(:all) clause to do a zero.stop would do the trick.

Before I start, has anyone else gone down this path?

Thanks.

Joe

Joe,

This functionality is baked into ChefSpec. The method you want is ChefZero::Server#reset.

Thanks,
Seth

On Mar 14, 2014, at 12:42 PM, Eric Herot eric.opscode@herot.com wrote:

Hi Joe,

Have you tried using test kitchen with the chef-zero provider? That pretty much handles this whole test harness automagically, including the port numbers on multiple instances, spin-up/down, etc.

Eric

On March 14, 2014 at 12:17:40 PM, Joe Nuspl (nuspl@nvwls.com) wrote:

I am writing rspec tests for tools that interact with the chef, i.e. pushing of new cookbooks to the chef-server, creating Chef::Node objects from asset-tracking system.

I was thinking of firing up a chef-zero instance to used as the backend for these tests. A couple issues I see:

  1. chef-zero requires a port to be specified. Since there may be multiple tests running simultaneously, need to use different ports. I suppose I could iterate over a range of ports and use that one if it succeeds.

  2. Teardown. I suppose an after(:all) clause to do a zero.stop would do the trick.

Before I start, has anyone else gone down this path?

Thanks.

Joe