0

I saw most of the community cookbooks have tests. As I read some articles those tests can be, simply put, described as unit tests (does the cookbook does what it says?) and integration tests (does it work on the OS?).

I setup a LAMP virtual environment using Vagrant and Chef community cookbooks. Now I would like to test it.

First I thought I am gonna run all the community's integration tests using Kitchen CI on my provisioned system. I thought that's one of the reasons the creators write those integration tests, so admins can put all the tests together and test their system. However after a small research I found out the ways the cookbooks are tested differ, so it doesn't seem easy to simply run all of them at once on my system.

Does that mean I should write tests on my own? For example using Kitchen CI and serverspec. I guess they doesn't need to be very fancy, because the community cookbooks are tested, but I still feel it would be a good idea to check if services are running and configuration files present.

What is the common workflow? Write a few tests on your own? Or just "believe" in the community cookbooks? Or there is a way to run the community's tests all together after the OS is provisioned?

tsusanka
  • 4,801
  • 7
  • 36
  • 42

2 Answers2

1

One way is to use the minitest-handler cookbook. If this cookbook is included in your run, then all minitest tests present in files/default/tests/ are executed at the end of your run, and the Chef run either fails if tests fail, or succeeds if all tests passed.

Then on top of the community tests, you add some specific tests to your service in your application-cookbook.

However, I have been noticing a lack of minitest tests, and more and more people using ServerSpec. From my brief investigation, running tests on your machine during a chef run is not something that you do using ServerSpec.

JeanMertz
  • 2,250
  • 2
  • 21
  • 26
  • thx, just to clarify: I can't take all the integration tests (let's assume from apache, php and mysql community cookbooks) and run them all together using Test Kitchen, right? – tsusanka Apr 29 '14 at 14:42
  • With minitest-handler, you don't "take all the integration tests". You simply add the minitest-handler cookbook to your run-list, and it then runs all the tests from all the cookbooks that have minitests in them and are included in your (expanded) run list, at the end of your run list. – JeanMertz May 01 '14 at 03:55
1

You could write tests just for your cookbook and to ensure the services are running correctly that your application requires.

For example, if you are using Apache you could use ServerSpec to ensure that the Apache server is running and serving content.

This would test that your application/wrapper cookbook installed all of the resources along with the resources you expect the community cookbooks to install.

pwelch
  • 11
  • 2
  • Yeah, the community cookbooks do that. However I thought it might be a good idea to check everything again after the node is completely provisioned with all the cookbooks. – tsusanka Apr 30 '14 at 06:59