Skip to content

Commit

Permalink
First draft at a skeleton framework for rspec-system-puppet tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
apenney committed May 25, 2013
1 parent 8884d6c commit 141198f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .nodeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
default_set: 'centos-64-x64'
sets:
'centos-59-x64':
nodes:
"main.foo.vm":
prefab: 'centos-59-x64'
'centos-64-x64':
nodes:
"main.foo.vm":
prefab: 'centos-64-x64'
'fedora-18-x64':
nodes:
"main.foo.vm":
prefab: 'fedora-18-x64'
'debian-607-x64':
nodes:
"main.foo.vm":
prefab: 'debian-607-x64'
'debian-70rc1-x64':
nodes:
"main.foo.vm":
prefab: 'debian-70rc1-x64'
'ubuntu-server-10044-x64':
nodes:
"main.foo.vm":
prefab: 'ubuntu-server-10044-x64'
'ubuntu-server-12042-x64':
nodes:
"main.foo.vm":
prefab: 'ubuntu-server-12042-x64'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source :rubygems

group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'rspec-system-puppet', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'rspec-system/rake_task'
26 changes: 26 additions & 0 deletions spec/spec_helper_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rspec-system/spec_helper'
require 'rspec-system-puppet/helpers'

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

# Enable colour in Jenkins
c.tty = true

# This is where we 'setup' the nodes before running our tests
c.system_setup_block = proc do
# TODO: find a better way of importing this into this namespace
include RSpecSystemPuppet::Helpers

# Install puppet
puppet_install
puppet_master_install

# Replace mymodule with your module name
puppet_module_install(:source => proj_root, :module_name => 'apache')
system_run('puppet module install puppetlabs-firewall')
system_run('puppet module install ripienaar-concat')
system_run('puppet module install puppetlabs-stdlib')
end
end
29 changes: 29 additions & 0 deletions spec/system/basic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper_system'

# Here we put the more basic fundamental tests, ultra obvious stuff.
describe "basic tests:" do
it 'make sure we have copied the module across' do
# No point diagnosing any more if the module wasn't copied properly
system_run("ls /etc/puppet/modules/apache") do |r|
r[:exit_code].should == 0
r[:stdout].should =~ /Modulefile/
r[:stderr].should == ''
end
end

it 'my class should work with no errors' do
pp = <<-EOS
class { 'apache': }
EOS

# Run it once and make sure it doesn't bail with errors
puppet_apply(pp) do |r|
r.exit_code.should_not eq(1)
end

# Run it again and make sure no changes occurred this time, proving idempotency
puppet_apply(pp) do |r|
r.exit_code.should == 0
end
end
end
17 changes: 17 additions & 0 deletions spec/system/class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper_system'

describe 'apache class' do
it 'should install apache' do
if system_node.facts['osfamily'] == 'Debian'
system_run('dpkg --get-selections | grep apache2') do |r|
r.stdout.should =~ /^apache2\s+install$/
r.exit_code.should == 0
end
elsif system_node.facts['osfamily'] == 'RedHat'
system_run('rpm -q httpd') do |r|
r.stdout.should =~ /httpd/
r.exit_code.should == 0
end
end
end
end

0 comments on commit 141198f

Please sign in to comment.