-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from evertrue/add-test-goodies
Add unit & integration testing, tied in to Travis
- Loading branch information
Showing
11 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
driver: | ||
name: vagrant | ||
|
||
provisioner: | ||
name: chef_zero | ||
|
||
platforms: | ||
- name: ubuntu-12.04 | ||
- name: ubuntu-14.04 | ||
- name: centos-5.10 | ||
- name: centos-6.5 | ||
|
||
suites: | ||
- name: default | ||
run_list: | ||
- recipe[motd::default] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ rvm: | |
- 2.0 | ||
- 2.1 | ||
script: | ||
- bundle exec rubocop | ||
- bundle exec foodcritic -f any . | ||
- bundle exec rake travis |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://supermarket.getchef.com' | ||
|
||
metadata |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
source 'https://rubygems.org' | ||
|
||
group :lint do | ||
gem 'foodcritic' | ||
gem 'rubocop' | ||
group :test, :development do | ||
gem 'rake' | ||
end | ||
|
||
group :test do | ||
gem 'berkshelf', '~> 3.1' | ||
gem 'chefspec', '~> 4.0' | ||
gem 'foodcritic', '~> 3.0' | ||
gem 'rubocop', '~> 0.24' | ||
|
||
gem 'test-kitchen', '~> 1.2' | ||
gem 'kitchen-vagrant', '~> 0.14' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'bundler/setup' | ||
require 'rubocop/rake_task' | ||
require 'foodcritic' | ||
require 'rspec/core/rake_task' | ||
require 'kitchen' | ||
|
||
namespace :style do | ||
desc 'Run Ruby style checks' | ||
RuboCop::RakeTask.new(:ruby) | ||
|
||
desc 'Run Chef style checks' | ||
FoodCritic::Rake::LintTask.new(:chef) do |t| | ||
t.options = { fail_tags: ['any'] } | ||
end | ||
end | ||
|
||
desc 'Run all style checks' | ||
task style: ['style:chef', 'style:ruby'] | ||
|
||
desc 'Run ChefSpec unit tests' | ||
RSpec::Core::RakeTask.new(:unit) do |t| | ||
t.rspec_opts = '--color --format progress' | ||
end | ||
|
||
desc 'Run Test Kitchen integration tests' | ||
task :integration do | ||
Kitchen.logger = Kitchen.default_file_logger | ||
Kitchen::Config.new.instances.each do |instance| | ||
instance.test(:always) | ||
end | ||
end | ||
|
||
# The default rake task should just run it all | ||
task default: %w(style integration) | ||
|
||
task travis: %w(style) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'spec_helper' | ||
|
||
describe 'motd::cow' do | ||
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } | ||
|
||
it 'adds a cow motd' do | ||
expect(chef_run).to create_motd('50-cow') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe 'motd::default' do | ||
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } | ||
|
||
%w(cow knife_status).each do |recipe| | ||
it "includes the `#{recipe}` recipe" do | ||
expect(chef_run).to include_recipe "motd::#{recipe}" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe 'motd::knife_status' do | ||
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } | ||
|
||
before do | ||
File.stub(:directory?).and_call_original | ||
File.stub(:directory?).with('/etc/update-motd.d').and_return(true) | ||
end | ||
|
||
it 'adds a knife status motd' do | ||
expect(chef_run).to create_motd('98-knife-status') | ||
end | ||
|
||
it "creates #{Chef::Config[:file_cache_path]}/handlers directory" do | ||
expect(chef_run).to create_directory("#{Chef::Config[:file_cache_path]}/handlers").with( | ||
mode: 00755, | ||
) | ||
end | ||
|
||
it 'adds a Chef handler' do | ||
expect(chef_run).to create_template("#{Chef::Config[:file_cache_path]}/handlers/knife_status.rb").with( | ||
mode: 00644, | ||
source: 'knife_status_handler.rb', | ||
) | ||
end | ||
|
||
it 'enables Motd::KnifeStatus as a Chef handler' do | ||
expect(chef_run).to enable_chef_handler('Motd::KnifeStatus') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'chefspec' | ||
require 'chefspec/berkshelf' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'spec_helper' | ||
|
||
describe 'MOTD' do | ||
if os[:family] == 'Ubuntu' | ||
describe file '/etc/update-motd.d/50-cow' do | ||
it { should be_file } | ||
it { should be_mode '755' } | ||
it { should be_owned_by 'root' } | ||
it { should be_grouped_into 'root' } | ||
its(:content) do | ||
should match(/This is (\e\[0;34;49m)?default-ubuntu-(.*?)(\e\[0m)?, a vagrantup\.com _default server/) | ||
end | ||
end | ||
|
||
describe file '/etc/update-motd.d/98-knife-status' do | ||
it { should be_file } | ||
it { should be_mode '755' } | ||
it { should be_owned_by 'root' } | ||
it { should be_grouped_into 'root' } | ||
its(:content) { should include 'Last chef run:' } | ||
end | ||
|
||
describe file '/tmp/kitchen/cache/handlers' do | ||
it { should be_directory } | ||
it { should be_mode '755' } | ||
it { should be_owned_by 'root' } | ||
it { should be_grouped_into 'root' } | ||
end | ||
|
||
describe file '/tmp/kitchen/cache/handlers/knife_status.rb' do | ||
it { should be_file } | ||
it { should be_mode '644' } | ||
it { should be_owned_by 'root' } | ||
it { should be_grouped_into 'root' } | ||
its(:content) { should include 'KnifeStatus < Chef::Handler' } | ||
end | ||
else | ||
describe file '/etc/motd' do | ||
it { should be_file } | ||
it { should be_mode '644' } | ||
it { should be_owned_by 'root' } | ||
it { should be_grouped_into 'root' } | ||
its(:content) do | ||
should match(/This is (\e\[0;34;49m)?default-centos-(.*?)(\e\[0m)?, a vagrantup\.com _default server/) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'serverspec' | ||
require 'pathname' | ||
|
||
include Serverspec::Helper::Exec | ||
include Serverspec::Helper::DetectOS | ||
|
||
RSpec.configure do |c| | ||
c.before :all do | ||
c.path = '/sbin:/usr/sbin' | ||
end | ||
end |