Chapter 5. Introduction to Cucumber-Chef
Testing classes and methods is trivial. Mature unit testing frameworks exist that make it very easy to write simple code test-first. As the complexity increases and the need to test code that depends on other services arises, the frameworks become more sophisticated, allowing for the creation of mock services and the ability to stub out slow-responding or third-party interfaces.[15] If the test requirement is to exercise the code end-to-end, the complexity grows once more, and it becomes necessary to use specialist testing libraries for testing network services, or JavaScript.
Testing code that builds an entire infrastructure is a different proposition altogether. Not only do we need sophisticated libraries of code to verify the intended behavior of our systems, we need to be able to build and install the systems themselves. Consider the following test:
Scenario: Bluepill restarts Unicorn Given I have a newly installed Ubuntu machine managed by Chef And I apply the Unicorn role And I apply the Bluepill role And the Unicorn service is running When I kill the Unicorn process Then within 2 seconds the Unicorn process should be running again
To test this manually, we would need to find a machine, install Ubuntu on it, bootstrap it with Chef, apply the role, run Chef, log onto the machine, check that Unicorn is running, kill Unicorn, then finally check that it has restarted. This would be tremendously time-consuming, and expensive—so much so that ...
Get Test-Driven Infrastructure with Chef now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.