Last active
December 22, 2015 16:58
-
-
Save wickett/6502427 to your computer and use it in GitHub Desktop.
Test Driven Infra with Chef example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
group :test do | |
gem 'chefspec', '~> 1.3' | |
gem 'foodcritic', '~> 2.1' | |
gem 'strainer', '~> 3.0' | |
gem 'test-kitchen', '~> 1.0.0.alpha' | |
gem 'kitchen-lxc', '~> 0.0.1.beta1' | |
gem 'knife-spork', '~> 1.0.17' | |
gem 'hipchat', '~> 0.10.0' | |
gem 'guard', '~> 1.8' | |
gem 'guard-foodcritic', '~> 1.0' | |
gem 'guard-rspec', '~> 3.0' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Replace USERNAME with your username! | |
describe 'USERNAME-myface::default' do | |
let(:chef_run) do | |
run = ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04') | |
run.converge('USERNAME-myface::default') | |
end | |
it 'installs apache2' do | |
expect(chef_run).to install_package('apache2') | |
end | |
it 'starts the apache2 service' do | |
expect(chef_run).to start_service('apache2') | |
end | |
it 'sets apache2 to start on boot' do | |
expect(chef_run).to set_service_to_start_on_boot 'apache2' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chefspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard :rspec, cli: '--color', all_on_start: false do | |
watch(%r{^spec/.+_spec\.rb$}) | |
watch(%r{recipes/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | |
watch('spec/spec_helper.rb') { 'spec' } | |
end | |
guard :foodcritic, cookbook_paths: '.', all_on_start: false do | |
watch(%r{attributes/.+\.rb$}) | |
watch(%r{providers/.+\.rb$}) | |
watch(%r{recipes/.+\.rb$}) | |
watch(%r{resources/.+\.rb$}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knife: bundle exec knife cookbook test $COOKBOOK | |
foodcritic: bundle exec foodcritic $SANDBOX/$COOKBOOK -f any | |
rspec: (cd $COOKBOOK && bundle exec rspec --color --format documentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package 'apache2' | |
service 'apache2' do | |
action [:enable, :start] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle install --path /var/lib/jenkins/support/vendor | |
bundle exec strainer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Replace USERNAME with your username! | |
describe 'USERNAME-myface::default' do | |
let(:chef_run) do | |
run = ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04') | |
run.converge('USERNAME-myface::default') | |
end | |
it 'installs apache2' do | |
expect(chef_run).to install_package('apache2') | |
end | |
it 'starts the apache2 service' do | |
expect(chef_run).to start_service('apache2') | |
end | |
it 'sets apache2 to start on boot' do | |
expect(chef_run).to set_service_to_start_on_boot 'apache2' | |
end | |
it 'creates the default template' do | |
expect(chef_run).to create_file('/var/www/index.html') | |
end | |
it 'creates the site with the correct content' do | |
template = chef_run.template('/var/www/index.html') | |
expect(template.owner).to eq('root') | |
expect(template.group).to eq('root') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package 'apache2' | |
service 'apache2' do | |
action [:enable, :start] | |
end | |
template '/var/www/index.html' do | |
owner 'root' | |
group 'root' | |
mode '0755' | |
source 'index.html.erb' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Welcome to <%= node['fqdn'] %></title> | |
</head> | |
<body> | |
<p>Here's everything you need to know about <%= node['fqdn'] %>:</p> | |
<pre><%= JSON.pretty_generate(node.to_hash) %></pre> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
driver_plugin: lxc | |
driver_config: | |
use_sudo: true | |
platforms: | |
- name: ubuntu-12.04 | |
driver_config: | |
base_container: ubuntu_12.04 | |
username: ubuntu | |
password: ubuntu | |
suites: | |
- name: default | |
run_list: ["recipe[myface]"] | |
attributes: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knife: bundle exec knife cookbook test $COOKBOOK | |
foodcritic: bundle exec foodcritic $SANDBOX/$COOKBOOK -f any | |
rspec: (cd $COOKBOOK && bundle exec rspec --color --format documentation) | |
kitchen: (cd $COOKBOOK && bundle exec kitchen test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
James |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment