Setup Test Kitchen in a Chef Cookbook

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives examples to using Test Kitchen in a Chef cookbook.


Prerequisites


Create a Chef Cookbook (Optional)

  1. Use Knife command to create a cookbook shell
    chef exec knife cookbook create <cookbook name> --cookbook-path <path>
    
    Example
    chef exec knife cookbook create mycookbook --cookbook-path $HOME/Development/Cookbooks
    
  2. Update metadata.rb


Add Test Kitchen Configurations to Cookbook

Either you can manually create the .kitchen.yml, spec directory and test directories or do the following:
I usually copy from one of my other cookbooks

  1. Change directories to the cookbook root.
    cd $HOME/Development/Cookbooks/mycookbook
    
  2. Run Kitchen Initialization command
    chef exec kitchen init
    


Add BerkShelf Configurations to Cookbook

Either you can manually create the Berksfile and Gemfile or do the following:
I usually copy from one of my other cookbooks

  1. Change directories to the cookbook root.
    cd $HOME/Development/Cookbooks/mycookbook
    
  2. Run Kitchen Initialization command
    chef exec berks init
    

Gnome-sticky-notes-applet You don't need the Vagrantfile because Test Kitchen will handle the generation of the file and save it under the temp .kitchen directory as needed. Also I don't use the Thorfile. So I delete it as well.


Configure Test Kitchen

  1. Edit the .kitchen.yml file with vim or whatever editor you like.
    vim .kitchen.yml
    
  2. Test Kitchen Config Examples


Create Integration Test Directories

Gnome-sticky-notes-applet The Test Kitchen Test Suite name/s must match the directory structure under test/integration/<test suite name>.

formatted text
cat /var/log/messages

Icon-Tip-Square-Green.png Gnome-sticky-notes-applet


Related Articles