Skip to content

Commit

Permalink
add rspec-system-puppet infrastructure + basic system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Sep 30, 2013
1 parent 1f34762 commit 6029324
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Gemfile.lock
*.orig
*.rej
*.patch
.rspec_system/
11 changes: 11 additions & 0 deletions .nodeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
default_set: 'centos-64-x64'
sets:
'centos-64-x64':
nodes:
'main.vm':
prefab: 'centos-64-x64'
'debian-607-x64':
nodes:
'main.vm':
prefab: 'debian-607-x64'
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ gem 'rake'
gem 'puppetlabs_spec_helper'
gem 'puppet-lint'
gem 'puppet-syntax'
gem 'rspec-system', :require => false
gem 'rspec-system-puppet', :require => false
gem 'rspec-system-serverspec', :require => false
gem 'serverspec', :require => false

# vim:ft=ruby
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'rspec-system/rake_task'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-lint/tasks/puppet-lint'

Expand Down
28 changes: 28 additions & 0 deletions spec/spec_helper_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rspec-system/spec_helper'
require 'rspec-system-puppet/helpers'
require 'rspec-system-serverspec/helpers'

include RSpecSystemPuppet::Helpers

include Serverspec::Helper::RSpecSystem
include Serverspec::Helper::DetectOS

RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

# Enable colour
c.tty = true

c.include RSpecSystemPuppet::Helpers

# This is where we 'setup' the nodes before running our tests
c.before :suite do
# Install puppet
puppet_install

# Install modules and dependencies
puppet_module_install(:source => proj_root, :module_name => 'smartd')
shell('puppet module install puppetlabs-stdlib')
end
end
42 changes: 42 additions & 0 deletions spec/system/smartd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'spec_helper_system'

describe 'smartd class' do
case node.facts['osfamily']
when 'RedHat', 'Debian'
package_name = 'smartmontools'
service_name = 'smartd'
end

describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'smartd': }
EOS

# Run it twice and test for idempotency
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.refresh
r.exit_code.should be_zero
end
end
end

describe package(package_name) do
it { should be_installed }
end

describe service(service_name) do
it { should be_running }
it { should be_enabled }
end

describe file('/etc/smartd.conf') do
it { should be_file }
it { should contain([
'DEFAULT -m root -M daily',
'DEVICESCAN',
]) }
end
end

0 comments on commit 6029324

Please sign in to comment.