Skip to content

Commit

Permalink
Merge pull request #1 from jhoblitt/system-tests
Browse files Browse the repository at this point in the history
System tests
  • Loading branch information
Joshua Hoblitt committed Dec 27, 2013
2 parents 88ca870 + 95cc94a commit 3e91613
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 30 deletions.
6 changes: 4 additions & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
stdlib:
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '3.0.0'
symlinks:
"policykit": "#{source_dir}"
policykit: "#{source_dir}"
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pkg/
spec/fixtures/
Gemfile.lock
*.orig
*.rej
*.patch
pkg/
*.rej
.rspec_system/
spec/fixtures/manifests/
spec/fixtures/modules/
*.swp
62 changes: 62 additions & 0 deletions .nodeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
default_set: 'centos-64-x64'
sets:
'centos-58-x64':
nodes:
"main":
prefab: 'centos-58-x64'
'centos-59-x64':
nodes:
"main":
prefab: 'centos-59-x64'
'centos-63-x64':
nodes:
"main":
prefab: 'centos-63-x64'
'centos-64-x64':
nodes:
"main":
prefab: 'centos-64-x64'
'fedora-18-x64':
nodes:
"main":
prefab: 'fedora-18-x64'
'debian-606-x64':
nodes:
"main":
prefab: 'debian-606-x64'
'debian-607-x64':
nodes:
"main":
prefab: 'debian-607-x64'
'debian-70rc1-x64':
nodes:
"main":
prefab: 'debian-70rc1-x64'
'ubuntu-server-1004-x64':
nodes:
"main":
prefab: 'ubuntu-server-1004-x64'
'ubuntu-server-10044-x64':
nodes:
"main":
prefab: 'ubuntu-server-10044-x64'
'ubuntu-server-1204-x64':
nodes:
"main":
prefab: 'ubuntu-server-1204-x64'
'ubuntu-server-12042-x64':
nodes:
"main":
prefab: 'ubuntu-server-12042-x64'
'sles-11sp1-x64':
nodes:
"main":
prefab: 'sles-11sp1-x64'
'centos-64-x64-multi':
default_node: 'first'
nodes:
"first":
prefab: 'centos-64-x64'
"second":
prefab: 'centos-64-x64'
14 changes: 8 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ else
gem 'puppet', :require => false
end

gem 'rake'
gem 'puppetlabs_spec_helper'
gem 'puppet-lint'
gem 'puppet-syntax'

# vim:ft=ruby
gem 'rake', :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', '>=2', :require => false
gem 'serverspec', :require => false
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ project_page 'https://github.com/jhoblitt/puppet-policykit'
source 'https://github.com/jhoblitt/puppet-policykit.git'
summary 'Manages the policykit package'
description 'Manages the policykit package'
dependency 'puppetlabs/stdlib', '>= 1.0.0'
dependency 'puppetlabs/stdlib', '>= 3.0.0'
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-lint/tasks/puppet-lint'
require 'rspec-system/rake_task'

PuppetLint.configuration.send("disable_class_inherits_from_params_class")
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", 'tests/**/*.pp']
PuppetLint.configuration.ignore_paths = [
'pkg/**/*.pp',
'spec/**/*.pp',
'tests/**/*.pp',
]

task :default => [
:syntax,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

case $::osfamily {
'redhat': {
case $::lsbmajdistrelease {
case $::operatingsystemmajrelease {
6: {
$policykit_package = 'polkit'
$policykit_local_path = '/etc/polkit-1/localauthority/50-local.d'
}
default: {
fail("Module ${module_name} is not supported on lsbmajdistrelease ${::lsbmajdistrelease}")
fail("Module ${module_name} is not supported on operatingsystemmajrelease ${::operatingsystemmajrelease}")
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions spec/classes/policykit_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

describe 'policykit::params', :type => :class do
describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
}
end
let(:facts) {{ :osfamily => 'RedHat' }}

describe 'el6.x' do
before { facts[:lsbmajdistrelease] = '6' }
before { facts[:operatingsystemmajrelease] = '6' }

it { should include_class('policykit::params') }
it { should contain_class('policykit::params') }
end

describe 'unsupported lsbmajdistrelease' do
before { facts[:lsbmajdistrelease] = '7' }
before { facts[:operatingsystemmajrelease] = '7' }

it 'should fail' do
expect { should include_class('policykit::params') }.
to raise_error(Puppet::Error, /not supported on lsbmajdistrelease 7/)
expect { should contain_class('policykit::params') }.
to raise_error(Puppet::Error, /not supported on operatingsystemmajrelease 7/)
end
end
end
Expand All @@ -33,7 +29,7 @@
end

it 'should fail' do
expect { should include_class('policykit::params') }.
expect { should contain_class('policykit::params') }.
to raise_error(Puppet::Error, /not supported on Debian/)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/policykit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
:lsbmajdistrelease => '6',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '6',
}
end

Expand Down
4 changes: 2 additions & 2 deletions spec/defines/localauthority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
describe 'policykit::localauthority', :type => :define do
let :facts do
{
:osfamily => 'RedHat',
:lsbmajdistrelease => '6',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '6',
}
end

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

include RSpecSystemPuppet::Helpers

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 => 'policykit')
shell('puppet module install puppetlabs-stdlib')
end
end
29 changes: 29 additions & 0 deletions spec/system/localauthority_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper_system'

describe 'policykit::localauthority define' do
describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
policykit::localauthority { 'disable suspend':
identity => 'unix-user:*',
action => 'org.freedesktop.upower.suspend',
result_active => 'no',
result_any => 'no',
result_inactive => 'no',
}
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 file('/etc/polkit-1/localauthority/50-local.d/disable_suspend.pkla') do
it { should be_file }
end
end
32 changes: 32 additions & 0 deletions spec/system/policykit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper_system'

describe 'policykit class' do
case node.facts['osfamily']
when 'RedHat', 'Debian'
package_name = 'polkit'
end

describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
include policykit
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 file('/etc/polkit-1/localauthority/50-local.d') do
it { should be_directory }
end
end

0 comments on commit 3e91613

Please sign in to comment.