chef-infratest-kitchenserverspec

How to setup test preconditions before a ServerSpec test?


I am writing a simple cookbook that will be used to deploy an SSL proxy onto a server. This cookbook will ultimately be used by other cookbooks that deploy web services in order to set up an SSL proxy in front of them, but for the purpose of testing the proxy cookbook itself, there is no such service behind it. My basic testing strategy for this cookbook is as follows:

  1. Converge the box with test-kitchen
  2. Use ServerSpec (or possibly Bats) with test-kitchen to
    1. Setup test by starting a python SimpleHTTPServer on the box listing on the port that the proxy was configured to forward to, and create in index.html file for it to serve.
    2. Assert that when I hit https://localhost I get the file that SimpleHTTPServer is serving.
    3. Assert a few more things about the proxy (all of which require that there be a service behind it.)
  3. Teardown. No real need to tear anything down, just let test-kitchen destroy the box.

So my question is, what is the right way to set up these sort of test preconditions using test-kitchen and ServerSpec and/or bats?


Solution

  • If the setup and teardown truly aren't part of what I'm testing, then I usually just do them in Ruby somewhere that runs before each test (often, in spec_helper.rb). Since serverspec is just literally running ruby code line by line on a test-kitchen instance, it doesn't feel necessary to me to have something in serverspec that offers setup/teardown functionality (in other words, there's no ordering issues or repeated tests that would require calling a setup or teardown method).