I recently worked on a Chef Cookbook development. I learned a very nice and useful way to test my changes without affecting any other Cookbooks, applications. I have explained it below. I am still a beginner at this, let me know if you are aware of a better approach ☺
Let’s assume that we need to make changes in cookbook named new-app, following is how I test changes:
Step 1: Check the available versions of a cookbook on chef server
knife cookbook show new-app
Step 2: Choose a very small version number x.y.z, smaller than the smallest number in output of previous command, I like to use 0.0.1
Step 3: In your local copy of cookbook, update the version number in metadata.rb file to x.y.z.
Step 4: Make the changes you intend to test.
Step 5: Upload the cookbook using following command
knife cookbook upload new-app -o /path/to/cookbook's/parent/directory
Step 6: Test the cookbook specific version
6.1: If you use cookbook name in run list directly
chef-client -o 'recipe[email@example.com]'
6.2: If you provide run list arguments through json file
chef-client -j runlist.json
6.3 If you provide run list through role
chef-client -o 'role[new-app-role]'
description "NEW APP SERVICE"
Step 7: After changes have been tested, delete the test version from server
knife cookbook delete new-app x.y.z -y