Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have heard
about chefSpec but not very much familiar and used to …

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

Hi,

sudo knife bootstrap --sudo -x -P -r “recipe [your_cookbook_name]”

above command will do bootstrap and it will install cookbook.

Regards,
PullaReddy
From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,
I would like to know how to do unit testing of chef cookbooks. I have heard about chefSpec but not very much familiar and used to …

My team had developed few cookbooks and would like to know the code coverage, etc.
Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

I wouldn’t necessarily call that testing, exactly, also, the sudo might be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of our recipes. It’s fast (no convergence required), and lets you follow a TDD mentality (write your ChefSpec assertions first, then write your recipe).

On the other hand, integration tests are essential to determining that your cookbook actually did what you want it to do. For this, we utilize Test Kitchen, backed by either Vagrant or EC2, and Serverspec as our assertion library. This allows you to write tests, using Rspec syntax, that asset that the final result of your convergence has what you need (services are running, ports are being listened on, files exist & have certain content, etc.)

Between these two test libraries, we have grown in confidence regarding our cookbooks.


Jeff Byrnes
Operations Engineer
EverTrue
@berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy (mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r “recipe [your_cookbook_name]”

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have heard about chefSpec but not very much familiar and used to …

My team had developed few cookbooks and would like to know the code coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

Thanks Jeff for sharing useful info.

I will work more on ChefSpec. do you have any documentation link for
chefSpec and Rspec.

Thanks & Regards,
Sachin Kumar

On Tue, Oct 28, 2014 at 4:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I wouldn’t necessarily call that testing, exactly, also, the sudo might
be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of our
recipes. It’s fast (no convergence required), and lets you follow a TDD
mentality (write your ChefSpec assertions first, then write your recipe).

On the other hand, integration tests are essential to determining that
your cookbook actually did what you want it to do. For this, we utilize
Test Kitchen, backed by either Vagrant or EC2, and Serverspec
http://serverspec.org as our assertion library. This allows you to
write tests, using Rspec syntax, that asset that the final result of your
convergence has what you need (services are running, ports are being
listened on, files exist & have certain content, etc.)

Between these two test libraries, we have grown in confidence regarding
our cookbooks.

--
Jeff Byrnes
Operations Engineer
EverTrue http://www.evertrue.com/
@berkleebassist http://twitter.com/berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy (
mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r
"recipe [your_cookbook_name]"

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have
heard about chefSpec but not very much familiar and used to ..

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

Hi Sachin,

you might want to check out the "Test-driven Infrastructure with Chef
(2nd Edition)" book for a broad coverage of the topic:

It handles all things testing:

  • basic syntax checks via knife cookbook test
  • codestyle checks via foodcritic
  • unit testing via chefspec and fauxhai
  • integration testing via kitchen-ci and serverspec
  • plus some approaches on testing whole infrastructures (rather than
    single servers)
  • plus cookbook dependency management via berkshelf (vs. traditional
    monolithic chef repo style)

The code examples might be slightly out of date if you are
practicing them with the latest version of the tools (we live in a
fast evolving world ;-)), but conceptually things should be pretty
stable and if you stick with the versions mentioned in the book you
should be safe.

HTH, Torben

On Tue, Oct 28, 2014 at 12:13 PM, Sachin Gupta
guptasachin1112mrt@gmail.com wrote:

Thanks Jeff for sharing useful info.

I will work more on ChefSpec. do you have any documentation link for
chefSpec and Rspec.

Thanks & Regards,
Sachin Kumar

On Tue, Oct 28, 2014 at 4:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I wouldn’t necessarily call that testing, exactly, also, the sudo might
be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of our
recipes. It’s fast (no convergence required), and lets you follow a TDD
mentality (write your ChefSpec assertions first, then write your recipe).

On the other hand, integration tests are essential to determining that
your cookbook actually did what you want it to do. For this, we utilize Test
Kitchen, backed by either Vagrant or EC2, and Serverspec as our assertion
library. This allows you to write tests, using Rspec syntax, that asset that
the final result of your convergence has what you need (services are
running, ports are being listened on, files exist & have certain content,
etc.)

Between these two test libraries, we have grown in confidence regarding
our cookbooks.

--
Jeff Byrnes
Operations Engineer
EverTrue
@berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy
(mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r
"recipe [your_cookbook_name]"

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have
heard about chefSpec but not very much familiar and used to ..

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

Sachin,

The best resource I have found for ChefSpec is the documentation on
GitHub. The Readme (GitHub - chefspec/chefspec: Write RSpec examples and generate coverage reports for Chef recipes!) gives a
fantastic overview, and the examples directory shows specific examples of
how to test individual resources (
https://github.com/sethvargo/chefspec/tree/master/examples). I refer to
the examples daily.

Nolan

On Tue, Oct 28, 2014 at 7:41 AM, Torben Knerr mail@tknerr.de wrote:

Hi Sachin,

you might want to check out the "Test-driven Infrastructure with Chef
(2nd Edition)" book for a broad coverage of the topic:

Amazon.com

It handles all things testing:

  • basic syntax checks via knife cookbook test
  • codestyle checks via foodcritic
  • unit testing via chefspec and fauxhai
  • integration testing via kitchen-ci and serverspec
  • plus some approaches on testing whole infrastructures (rather than
    single servers)
  • plus cookbook dependency management via berkshelf (vs. traditional
    monolithic chef repo style)

The code examples might be slightly out of date if you are
practicing them with the latest version of the tools (we live in a
fast evolving world ;-)), but conceptually things should be pretty
stable and if you stick with the versions mentioned in the book you
should be safe.

HTH, Torben

On Tue, Oct 28, 2014 at 12:13 PM, Sachin Gupta
guptasachin1112mrt@gmail.com wrote:

Thanks Jeff for sharing useful info.

I will work more on ChefSpec. do you have any documentation link for
chefSpec and Rspec.

Thanks & Regards,
Sachin Kumar

On Tue, Oct 28, 2014 at 4:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I wouldn’t necessarily call that testing, exactly, also, the sudo
might
be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of our
recipes. It’s fast (no convergence required), and lets you follow a TDD
mentality (write your ChefSpec assertions first, then write your
recipe).

On the other hand, integration tests are essential to determining that
your cookbook actually did what you want it to do. For this, we utilize
Test
Kitchen, backed by either Vagrant or EC2, and Serverspec as our
assertion
library. This allows you to write tests, using Rspec syntax, that asset
that
the final result of your convergence has what you need (services are
running, ports are being listened on, files exist & have certain
content,
etc.)

Between these two test libraries, we have grown in confidence regarding
our cookbooks.

--
Jeff Byrnes
Operations Engineer
EverTrue
@berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy
(mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r
"recipe [your_cookbook_name]"

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have
heard about chefSpec but not very much familiar and used to ..

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

I’d back that the best ChefSpec resource is the GitHub README; also the issues & PRs offer valuable info as well.

--
Jeff Byrnes
@berkleebassist
Lead DevOps Engineer
EverTrue
704.516.4628

On October 28, 2014 at 12:25:46 PM, Nolan (nolan.davidson@gmail.com) wrote:

Sachin,

The best resource I have found for ChefSpec is the documentation on GitHub. The Readme (GitHub - chefspec/chefspec: Write RSpec examples and generate coverage reports for Chef recipes!) gives a fantastic overview, and the examples directory shows specific examples of how to test individual resources (https://github.com/sethvargo/chefspec/tree/master/examples). I refer to the examples daily.

Nolan

On Tue, Oct 28, 2014 at 7:41 AM, Torben Knerr mail@tknerr.de wrote:
Hi Sachin,

you might want to check out the "Test-driven Infrastructure with Chef
(2nd Edition)" book for a broad coverage of the topic:

It handles all things testing:

  • basic syntax checks via knife cookbook test
  • codestyle checks via foodcritic
  • unit testing via chefspec and fauxhai
  • integration testing via kitchen-ci and serverspec
  • plus some approaches on testing whole infrastructures (rather than
    single servers)
  • plus cookbook dependency management via berkshelf (vs. traditional
    monolithic chef repo style)

The code examples might be slightly out of date if you are
practicing them with the latest version of the tools (we live in a
fast evolving world ;-)), but conceptually things should be pretty
stable and if you stick with the versions mentioned in the book you
should be safe.

HTH, Torben

On Tue, Oct 28, 2014 at 12:13 PM, Sachin Gupta
guptasachin1112mrt@gmail.com wrote:

Thanks Jeff for sharing useful info.

I will work more on ChefSpec. do you have any documentation link for
chefSpec and Rspec.

Thanks & Regards,
Sachin Kumar

On Tue, Oct 28, 2014 at 4:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I wouldn’t necessarily call that testing, exactly, also, the sudo might
be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of our
recipes. It’s fast (no convergence required), and lets you follow a TDD
mentality (write your ChefSpec assertions first, then write your recipe).

On the other hand, integration tests are essential to determining that
your cookbook actually did what you want it to do. For this, we utilize Test
Kitchen, backed by either Vagrant or EC2, and Serverspec as our assertion
library. This allows you to write tests, using Rspec syntax, that asset that
the final result of your convergence has what you need (services are
running, ports are being listened on, files exist & have certain content,
etc.)

Between these two test libraries, we have grown in confidence regarding
our cookbooks.

--
Jeff Byrnes
Operations Engineer
EverTrue
@berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy
(mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r
"recipe [your_cookbook_name]"

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have
heard about chefSpec but not very much familiar and used to ..

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta

Thanks Torben, Nolan and Jeff.

Currently I am referring GitHub documentation. I have few cookbooks (java,
weblogic, OHS) ready for unit testing.

Will share my findings with ChefSpec..

Thanks & Regards,
Sachin Gupta

On Tue, Oct 28, 2014 at 10:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I’d back that the best ChefSpec resource is the GitHub README; also the
issues & PRs offer valuable info as well.

--
Jeff Byrnes
@berkleebassist http://twitter.com/berkleebassist
Lead DevOps Engineer
EverTrue http://www.evertrue.com/
704.516.4628

On October 28, 2014 at 12:25:46 PM, Nolan (nolan.davidson@gmail.com)
wrote:

Sachin,

The best resource I have found for ChefSpec is the documentation on
GitHub. The Readme (GitHub - chefspec/chefspec: Write RSpec examples and generate coverage reports for Chef recipes!) gives a
fantastic overview, and the examples directory shows specific examples of
how to test individual resources (
https://github.com/sethvargo/chefspec/tree/master/examples). I refer to
the examples daily.

Nolan

On Tue, Oct 28, 2014 at 7:41 AM, Torben Knerr mail@tknerr.de wrote:

Hi Sachin,

you might want to check out the "Test-driven Infrastructure with Chef
(2nd Edition)" book for a broad coverage of the topic:

http://www.amazon.com/Test-Driven-Infrastructure-Chef-Behavior-Driven-Development/dp/1449372201?tag=eboosear-20

It handles all things testing:

  • basic syntax checks via knife cookbook test
  • codestyle checks via foodcritic
  • unit testing via chefspec and fauxhai
  • integration testing via kitchen-ci and serverspec
  • plus some approaches on testing whole infrastructures (rather than
    single servers)
  • plus cookbook dependency management via berkshelf (vs. traditional
    monolithic chef repo style)

The code examples might be slightly out of date if you are
practicing them with the latest version of the tools (we live in a
fast evolving world ;-)), but conceptually things should be pretty
stable and if you stick with the versions mentioned in the book you
should be safe.

HTH, Torben

On Tue, Oct 28, 2014 at 12:13 PM, Sachin Gupta
guptasachin1112mrt@gmail.com wrote:

Thanks Jeff for sharing useful info.

I will work more on ChefSpec. do you have any documentation link for
chefSpec and Rspec.

Thanks & Regards,
Sachin Kumar

On Tue, Oct 28, 2014 at 4:37 PM, Jeff Byrnes jeff@evertrue.com wrote:

I wouldn’t necessarily call that testing, exactly, also, the sudo
might
be unnecessary in their environment (dangerous, even).

With regards to ChefSpec, that’s how we handle doing unit testing of
our
recipes. It’s fast (no convergence required), and lets you follow a TDD
mentality (write your ChefSpec assertions first, then write your
recipe).

On the other hand, integration tests are essential to determining that
your cookbook actually did what you want it to do. For this, we
utilize Test
Kitchen, backed by either Vagrant or EC2, and Serverspec as our
assertion
library. This allows you to write tests, using Rspec syntax, that
asset that
the final result of your convergence has what you need (services are
running, ports are being listened on, files exist & have certain
content,
etc.)

Between these two test libraries, we have grown in confidence regarding
our cookbooks.

--
Jeff Byrnes
Operations Engineer
EverTrue
@berkleebassist

On October 28, 2014 at 5:17:20 AM, Malli Pulla Reddy
(mpreddy@jamcracker.com) wrote:

Hi,

sudo knife bootstrap --sudo -x -P -r
"recipe [your_cookbook_name]"

above command will do bootstrap and it will install cookbook.

Regards,

PullaReddy

From: Sachin Gupta [mailto:guptasachin1112mrt@gmail.com]
Sent: Tuesday, October 28, 2014 2:15 PM
To: chef@lists.opscode.com
Cc: sachin kumar
Subject: [chef] Unit Testing chef Cookbook

Hi All,

I would like to know how to do unit testing of chef cookbooks. I have
heard about chefSpec but not very much familiar and used to ..

My team had developed few cookbooks and would like to know the code
coverage, etc.

Any help would be highly appreciated.

Thanks & Regards,
Sachin Gupta