Skip to content

Commit

Permalink
Merge pull request #287 from jlambert121/acceptance
Browse files Browse the repository at this point in the history
enhance acceptance tests, update spec tests
  • Loading branch information
jlambert121 committed Dec 15, 2014
2 parents 3eeeb01 + b865fcc commit 08e36f0
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 96 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
language: ruby
bundler_args: --without development
bundler_args: --without system_tests
script: "bundle install && bundle exec rake validate && bundle exec rake test SPEC_OPTS='--format documentation'"
rvm:
- 1.8.7
- 1.9.3
Expand All @@ -8,10 +10,6 @@ rvm:
before_install:
- gem update --system 2.1.11
- gem --version
script:
- "rake lint"
- "rake syntax"
- "rake spec SPEC_OPTS='--format documentation'"
env:
- PUPPET_VERSION="~> 2.7.0"
- PUPPET_VERSION="~> 3.1.0"
Expand Down
17 changes: 10 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ source 'https://rubygems.org'

source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
group :development, :unit_tests do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'rspec-puppet', :require => false, :git => 'https://github.com/rodjek/rspec-puppet.git', :tag => 'v2.0.0'
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'puppet-blacksmith', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', "~> 2.2.4",:require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
gem 'json', :require => false
gem 'puppet-syntax', :require => false
gem 'metadata-json-lint', :require => false
gem 'vagrant-wrapper', :require => false
gem 'puppet-blacksmith', :require => false
gem 'rest-client', "1.6.8", :require => false
end
group :system_tests do
gem 'beaker-rspec', '~> 2.2.4', :require => false
gem 'serverspec', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
Expand Down
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ exclude_paths = [

PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.send("disable_autoloader_layout")
PuppetLint.configuration.send("disable_quoted_booleans")
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths

task :metadata do
sh "metadata-json-lint metadata.json"
end

desc "Run syntax, lint, and spec tests."
task :test => [
:syntax,
:lint,
:metadata,
:spec,
]
1 change: 0 additions & 1 deletion manifests/client/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
class sensu::client::service {


if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}
Expand Down
24 changes: 2 additions & 22 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'file': {
$filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')

define_plugins_dir { "${name}-${install_path}":
sensu::plugins_dir { "${name}-${install_path}":
path => $install_path,
purge => $purge,
recurse => $recurse,
Expand All @@ -72,7 +72,7 @@
'url' : {
$filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')

define_plugins_dir { "${name}-${install_path}":
sensu::plugins_dir { "${name}-${install_path}":
path => $install_path,
purge => $purge,
recurse => $recurse,
Expand Down Expand Up @@ -113,23 +113,3 @@

}
}
# This is to verify the install_dir exists without duplicate declarations
define define_plugins_dir (
$force,
$purge,
$recurse,
$path = $name,
) {
if ! defined(File[$path]) {
file { $path:
ensure => directory,
mode => '0555',
owner => 'sensu',
group => 'sensu',
recurse => $recurse,
purge => $purge,
force => $force,
require => Package['sensu'],
}
}
}
20 changes: 20 additions & 0 deletions manifests/plugins_dir.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This is to verify the install_dir exists without duplicate declarations
define sensu::plugins_dir (
$force,
$purge,
$recurse,
$path = $name,
) {
if ! defined(File[$path]) {
file { $path:
ensure => directory,
mode => '0555',
owner => 'sensu',
group => 'sensu',
recurse => $recurse,
purge => $purge,
force => $force,
require => Package['sensu'],
}
}
}
2 changes: 1 addition & 1 deletion manifests/repo/apt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

} else {
fail('This class requires puppet-apt module')
fail('This class requires puppetlabs-apt module')
}

}
2 changes: 1 addition & 1 deletion manifests/repo/yum.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if $sensu::repo_source {
$url = $sensu::repo_source
} else {
if $operatingsystemmajrelease == 7 {
if $::operatingsystemmajrelease == 7 {
$url = $sensu::repo ? {
'unstable' => "http://repos.sensuapp.org/yum-unstable/el/6/\$basearch/",
default => "http://repos.sensuapp.org/yum/el/6/\$basearch/"
Expand Down
81 changes: 71 additions & 10 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@
describe 'sensu class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do

context 'sensu' do
context 'ensure => present' do
context 'default' do
it 'should work with no errors' do
pp = <<-EOS
class { 'sensu':}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe service('sensu-client') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

end #default

context 'server => true, api => true' do
it 'should work with no errors' do
pp = <<-EOS
class { 'rabbitmq':
Expand All @@ -18,6 +36,12 @@ class { 'rabbitmq':
write_permission => '.*',
}
class { 'redis': }
EOS

# Set up dependencies
apply_manifest(pp, :catch_failures => true)

pp = <<-EOS
class { 'sensu':
server => true,
api => true,
Expand All @@ -28,14 +52,51 @@ class { 'sensu':
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)
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe service('sensu-server') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe service('sensu-client') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe service('sensu-api') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe command('curl localhost:4567/info') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match /sensu.*version/ }
end
end # server and api

context 'client => false' do
it 'should work with no errors' do
pp = <<-EOS
class { 'sensu':
client => false
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
shell('sleep 5') # Give services time to stop
apply_manifest(pp, :catch_changes => true)
end
it 'should start the API' do
shell('curl localhost:4567/info') do |curl|
expect(curl.stdout).to include 'sensu', 'version'
end

describe service('sensu-client') do
it { is_expected.not_to be_running }
it { is_expected.not_to be_enabled }
end
end
end
end

end #no client
end # sensu

end
11 changes: 0 additions & 11 deletions spec/acceptance/nodesets/centos-64-x64.yml

This file was deleted.

11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/centos-65-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
centos-65-x64:
roles:
- master
platform: el-6-x86_64
box : puppetlabs/centos-6.5-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-6.5-64-nocm
hypervisor : vagrant
CONFIG:
log_level: debug
type: foss
11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/centos-70-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
centos-70-x64:
roles:
- master
platform: el-7-x86_64
box : puppetlabs/centos-7.0-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm
hypervisor : vagrant
CONFIG:
log_level: verbose
type: foss
10 changes: 5 additions & 5 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
HOSTS:
ubuntu-server-12042-x64:
centos-70-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
platform: el-7-x86_64
box : puppetlabs/centos-7.0-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm
hypervisor : vagrant
CONFIG:
log_level: verbose
type: foss
11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/ubuntu-server-1204-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1204-x64:
roles:
- master
platform: ubuntu-12.04-amd64
box : puppetlabs/ubuntu-12.04-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/ubuntu-12.04-64-nocm
hypervisor : vagrant
CONFIG:
log_level: debug
type: foss
11 changes: 0 additions & 11 deletions spec/acceptance/nodesets/ubuntu-server-12042-x64.yml

This file was deleted.

11 changes: 11 additions & 0 deletions spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1404-x64:
roles:
- master
platform: ubuntu-14.04-amd64
box: puppetlabs/ubuntu-14.04-64-nocm
box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
hypervisor: vagrant
CONFIG:
log_level: debug
type: foss
9 changes: 3 additions & 6 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

it { should contain_sensu_check('mycheck').with(
:command => '/etc/sensu/somecommand.rb',
:handlers => '',
:interval => 60,
:subscribers => []
) }
Expand Down Expand Up @@ -70,7 +69,6 @@

it { should contain_sensu_check('mycheck_foobar').with(
:command => '/etc/sensu/somecommand.rb',
:handlers => '',
:interval => '60',
:subscribers => []
) }
Expand All @@ -87,7 +85,6 @@

it { should contain_sensu_check('mycheck_foo_bar').with(
'command' => '/etc/sensu/somecommand.rb',
'handlers' => '',
'interval' => '60',
'subscribers' => []
) }
Expand All @@ -107,17 +104,17 @@

context 'only client' do
let(:pre_condition) { 'class {"sensu": client => true, api => false, server => false}' }
it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Client::Service]' ]) }
it { should contain_sensu_check('mycheck').with(:notify => 'Class[Sensu::Client::Service]' ) }
end

context 'only server' do
let(:pre_condition) { 'class {"sensu": client => false, api => false, server => true}' }
it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Server::Service]' ]) }
it { should contain_sensu_check('mycheck').with(:notify => 'Class[Sensu::Server::Service]' ) }
end

context 'only api' do
let(:pre_condition) { 'class {"sensu": client => false, api => true, server => false}' }
it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Api::Service]' ]) }
it { should contain_sensu_check('mycheck').with(:notify => 'Class[Sensu::Api::Service]' ) }
end

context 'client and api' do
Expand Down
Loading

0 comments on commit 08e36f0

Please sign in to comment.