Skip to content

Commit

Permalink
Merge pull request #236 from petems/add_basic_beaker_spec
Browse files Browse the repository at this point in the history
Basic working Beaker spec for Sensu
  • Loading branch information
jamtur01 committed Aug 28, 2014
2 parents 64aa8a8 + be54125 commit a2ad727
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 6 deletions.
34 changes: 28 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
source 'https://rubygems.org'

puppetversion = ENV['PUPPET_VERSION']
gem 'puppet', puppetversion, :require => false
gem 'puppet-lint'
gem 'rspec-puppet'
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-syntax'
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', "~> 2.2.4",:require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
gem 'vagrant-wrapper', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

# vim:ft=ruby
41 changes: 41 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper_acceptance'

describe 'sensu class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do

context 'sensu' do
context 'ensure => present' do
it 'should work with no errors' do
pp = <<-EOS
class { 'rabbitmq':
ssl => false,
delete_guest_user => true,
}
-> rabbitmq_vhost { 'sensu': }
-> rabbitmq_user { 'sensu': password => 'secret' }
-> rabbitmq_user_permissions { 'sensu@sensu':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
}
class { 'redis': }
class { 'sensu':
server => true,
api => true,
purge_config => true,
rabbitmq_password => 'secret',
rabbitmq_host => 'localhost',
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end
it 'should start the API' do
shell('curl localhost:4567/info') do |curl|
expect(curl.stdout).to include 'sensu', 'version'
end
end
end
end
end
11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/centos-64-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
centos-64-x64:
roles:
- master
platform: el-6-x86_64
box: centos-64-x64-vbox4210-nocm
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor: vagrant
CONFIG:
log_level: verbose
type: foss
11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-12.04-amd64
box: ubuntu-server-12042-x64-vbox4210-nocm
box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor: vagrant
CONFIG:
log_level: verbose
type: foss
11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/ubuntu-server-12042-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-12.04-amd64
box: ubuntu-server-12042-x64-vbox4210-nocm
box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor: vagrant
CONFIG:
log_level: verbose
type: foss
45 changes: 45 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'beaker-rspec'

unless ENV['RS_PROVISION'] == 'no'
hosts.each do |host|
if host.is_pe?
install_pe
else
install_puppet
on host, "mkdir -p #{host['distmoduledir']}"
end
end
end

UNSUPPORTED_PLATFORMS = ['windows']

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

# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'sensu')
hosts.each do |host|
if fact('osfamily') == 'Debian'
# RubyGems missing on some Vagrant boxes
# Otherwise you'lll get a load of 'Provider gem is not functional on this host'
shell('apt-get install rubygems -y')
end
if fact('osfamily') == 'RedHat'
# RedHat needs EPEL for RabbitMQ and Redis
shell('wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && sudo rpm -Uvh epel-release-6*.rpm')
end
shell('/bin/touch /etc/puppet/hiera.yaml')
shell('puppet module install puppetlabs-stdlib --version 3.2.0', { :acceptable_exit_codes => [0,1] })
shell('puppet module install maestrodev/wget --version 1.4.5', { :acceptable_exit_codes => [0,1] })
shell('puppet module install puppetlabs-rabbitmq --version 4.1.0', { :acceptable_exit_codes => [0,1] })
shell('puppet module install fsalum-redis --version 1.0.0', { :acceptable_exit_codes => [0,1] })
shell('puppet module install puppetlabs/apt --version 1.6.0', { :acceptable_exit_codes => [0,1] })
end
end
end

0 comments on commit a2ad727

Please sign in to comment.