For change automation, integration testing is essential both verifying functionality and testing future changes that could affect a production systems. These changes can be either adding new features, changes the change platform, like Puppet to Chef or Chef to Docker as examples, or other components, e.g. unicorn to puma or passenger, Apache to Nginx, CentOS to Ubuntu, etc. that could affect the service.
One popular tool for this is ServerSpec, a framework that uses RSpec test framework for checking your servers are configured correctly. ServerSpec can execute tests locally, through SSH, WinRM, or using Docker API.
Getting Started with ServerSpec
Starting in a test directory, such as your vagrant directory with a server running, and Ruby previously installed, you can run the following to get started:
gem install serverspec
If you selected SSH and Vagrant as your environment, this will create similar to the following where $VBOX_HOSTNAME matches name of your vagrant system. Usually, unless you specified this, it will be set to the name ‘default’:
│ └── sample_spec.rb
Test Script Example
As a simple small example, here’s a test that checks for a user and group membership of the user vagrant.
Running the Tests
If you have rake gem installed you simply run:
Otherwise, if you do not have rake installed, or want to run tests on a single system out of many, you can type: