Many IT operations teams are used to managing infrastructure manually or with simple one-off scripts. This manual work and lack of verifiable behavior results in many issues and in uncertainty. In software development, Test Driven Development (TDD) is well recognized for improving design, increasing code quality, and allowing refactoring and better knowledge sharing.
Similar benefits can be gained in infrastructure projects when infrastructure is treated as code, driving that code development with tests. Configuration management tools such as Chef and Puppet allow infrastructure to be easily described as code and provide a complete support to introduce and run tests. This can allow development and operations teams to collaborate and confidently deliver working infrastructure code.
46. require 'spec_helper'
describe service('apache2') do
it { should be_running }
describe port(80) do
it { should be_listening }
end
end
httpd-cookbook/test/integration/server/serverspec/default_spec.
rb
51. require 'spec_helper'
describe 'httpd::default' do
let(:chef_run) {
ChefSpec::SoloRunner.converge(described_recipe)
}
it 'installs apache2 package' do
expect(chef_run).to install_package('apache2')
end
end
httpd-cookbook/spec/unit/recipes/default_spec.rb
61. require 'spec_helper'
describe 'httpd::default' do
let(:chef_run) {
ChefSpec::SoloRunner.converge(described_recipe)
}
it 'installs apache2 package' do
expect(chef_run).to install_package('apache2')
end
it 'starts apache2 service' do
expect(chef_run).to start_service('apache2')
end
end
httpd-cookbook/spec/unit/recipes/default_spec.rb
72. Service "apache2"
should be running
Port "80"
should be listening
Finished in 0.09441 seconds
2 example, 0 failures
Finished verifying <default-ubuntu-1404> (0m6.52s).
-----> Kitchen is finished. (0m31.77s)