Skip to content

Commit

Permalink
add simple rspec-system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Nov 8, 2013
1 parent d9fa183 commit c8f12f3
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pkg/
spec/fixtures/
Gemfile.lock
.rspec_system/
*.orig
*.rej
*.patch
*.swp
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'
13 changes: 8 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ else
gem 'puppet', :require => false
end

gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'puppet-syntax', :require => false
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'puppet-syntax', :require => false
gem 'rspec-system', :require => false
gem 'rspec-system-puppet', :require => false
gem 'rspec-system-serverspec', :require => false

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

PuppetSyntax.exclude_paths = ["spec/fixtures/**/*"]
PuppetLint.configuration.send("disable_class_inherits_from_params_class")
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 => 'udev')
shell('puppet module install puppetlabs-stdlib')
end
end
56 changes: 56 additions & 0 deletions spec/system/udev_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'spec_helper_system'

describe 'udev class' do
describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
class { 'udev': udev_log => 'debug' }
udev::rule { '51-android.rules':
content => 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"',
}
udev::rule { '60-raw.rules':
content => 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"',
}
EOS

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

describe package('udev') do
it { should be_installed }
end

describe file('/etc/udev/udev.conf') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
it { should contain 'udev_log="debug"' }
end

describe file('/etc/udev/rules.d/51-android.rules') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
it { should contain 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"' }
end

describe file('/etc/udev/rules.d/60-raw.rules') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
it { should contain 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"' }
end
end

0 comments on commit c8f12f3

Please sign in to comment.