Skip to content

Commit

Permalink
Merge pull request #13 from jlambert121/spec_tests
Browse files Browse the repository at this point in the history
initial spec tests
  • Loading branch information
jamtur01 committed Feb 24, 2013
2 parents 9996c6a + 21d4032 commit f4dd39f
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fixtures:
repositories:
apt: git://github.com/puppetlabs/puppetlabs-apt.git
stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git
symlinks:
sensu: "#{source_dir}"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sensu.komodoproject
pkg/*
spec/fixtures
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'

8 changes: 8 additions & 0 deletions spec/classes/sensu_init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

describe 'sensu', :type => :class do

it { should create_class('sensu') }

end

11 changes: 11 additions & 0 deletions spec/classes/sensu_package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe 'sensu::package', :type => :class do
let(:facts) { { :fqdn => 'testhost.domain.com' } }

it { should create_class('sensu::package') }
it { should include_class('sensu::repo') }
it { should contain_package('sensu').with_ensure('latest') }
it { should contain_sensu_clean_config('testhost.domain.com') }

end
51 changes: 51 additions & 0 deletions spec/classes/sensu_repo_apt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'sensu::repo::apt', :type => :class do

define 'with puppet-apt installed' do
context 'ensure: present' do
let(:facts) { { :apt::source => true, :apt::key => true } }
let(:params) { { :ensure => 'present', :repo => 'main' } }
it { should contain_apt__source('sensu').with(
'ensure' => 'present',
'location' => 'http://repos.sensuapp.org/apt',
'release' => 'sensu',
'repos' => 'main',
'include_src' => false,
'before' => 'Package[sensu]'
) }

it { should contain_apt__key('sensu').with(
'key' => '7580C77F',
'key_source' => 'http://repos.sensuapp.org/apt/pubkey.gpg'
) }
end

context 'ensure: absent' do
let(:facts) { { :apt::source => true, :apt::key => true } }
let(:params) { { :ensure => 'absent', :repo => 'main' } }
it { should contain_apt__source('sensu').with(
'ensure' => 'absent',
'location' => 'http://repos.sensuapp.org/apt',
'release' => 'sensu',
'repos' => 'main',
'include_src' => false,
'before' => 'Package[sensu]'
) }

it { should contain_apt__key('sensu').with(
'key' => '7580C77F',
'key_source' => 'http://repos.sensuapp.org/apt/pubkey.gpg'
) }
end
end

context 'without puppet-apt installed' do
let(:params) { { :ensure => 'present', :repo => 'main' } }
xit { should contain_fail('This class requires puppet-apt module') }
end

end


# if defined(apt::source) and defined(apt::key) {
53 changes: 53 additions & 0 deletions spec/classes/sensu_repo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'spec_helper'

describe 'sensu::repo', :type => :class do

it { should create_class('sensu::repo') }

['Debian', 'Ubuntu' ].each do |os|
describe "operatingsystem: #{os}" do
let(:facts) { { :operatingsystem => os } }
context 'no params' do
it { should contain_class('sensu::repo::apt').with_ensure('present') }
end

['present', 'absent'].each do |state|
context "ensure: #{state}" do
let(:params) { { :ensure => state } }
it { should contain_class('sensu::repo::apt').with_ensure(state) }
end
end
end
end

['Rhel', 'CentOS' ].each do |os|
describe "operatingsystem: #{os}" do
let(:facts) { { :operatingsystem => os } }
context 'no params' do
it { should contain_class('sensu::repo::yum').with_ensure('present') }
end

['present', 'absent'].each do |state|
context "ensure: #{state}" do
let(:params) { { :ensure => state } }
it { should contain_class('sensu::repo::yum').with_ensure(state) }
end
end
end
end

describe 'operatingsystem: Darwin' do
let(:facts) { { :operatingsystem => 'Darwin' } }
context 'no params' do
xit { should contain_alert }
end

['present', 'absent'].each do |state|
context "ensure => #{state}" do
let(:params) { { :ensure => state } }
xit { should contain_alert('Darwin not supported yet') }
end
end
end
end

30 changes: 30 additions & 0 deletions spec/classes/sensu_repo_yum_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

describe 'sensu::repo::yum', :type => :class do

context 'ensure: present' do
let(:params) { { :ensure => 'present', :repo => 'main' } }
it { should contain_yumrepo('sensu').with(
'enabled' => 1,
'baseurl' => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/',
'gpgcheck' => 0,
'before' => 'Package[sensu]'
) }
end

context 'ensure: absent' do
let(:params) { { :ensure => 'absent', :repo => 'main' } }
it { should contain_yumrepo('sensu').with(
'enabled' => 'absent',
'before' => 'Package[sensu]'
) }
end

context 'ensure: foo' do
let(:params) { { :ensure => 'foo', :repo => 'main' } }
it { should contain_yumrepo('sensu').with(
'enabled' => 'absent',
'before' => 'Package[sensu]'
) }
end
end
35 changes: 35 additions & 0 deletions spec/defines/sensu_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe 'sensu::check', :type => :define do
let(:title) { 'mycheck' }

context 'defaults' do
let(:params) { { :command => '/etc/sensu/somecommand.rb' } }

it { should contain_sensu_check_config('mycheck').with(
'realname' => 'mycheck',
'command' => '/etc/sensu/somecommand.rb',
'handlers' => [],
'interval' => '60',
'subscribers' => []
) }
end

context 'setting params' do
let(:params) { {
:command => '/etc/sensu/command2.rb',
:handlers => ['/handler1', '/handler2'],
:interval => '10',
:subscribers => ['all']
} }

it { should contain_sensu_check_config('mycheck').with(
'realname' => 'mycheck',
'command' => '/etc/sensu/command2.rb',
'handlers' => ['/handler1', '/handler2'],
'interval' => '10',
'subscribers' => ['all']
) }
end

end
74 changes: 74 additions & 0 deletions spec/defines/sensu_client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require 'spec_helper'

describe 'sensu::client', :type => :define do
let(:title) { 'myclient' }

context 'defaults' do
let(:facts) { { :ipaddress => '2.3.4.5', :fqdn => 'host.domain.com' } }
let(:params) { { :rabbitmq_password => 'asdfjkl' } }

it { should include_class('sensu::package') }
it { should contain_sensu__rabbitmq('client').with(
'ssl_cert_chain' => '',
'ssl_private_key' => '',
'port' => '5671',
'host' => 'localhost',
'user' => 'sensu',
'vhost' => '/sensu',
'password' => 'asdfjkl'
) }

it { should contain_sensu_client_config('host.domain.com').with(
'client_name' => 'myclient',
'address' => '2.3.4.5',
'subscriptions' => []
) }

it { should contain_service('sensu-client').with(
'ensure' => 'running',
'enable' => true,
'hasrestart' => true,
'require' => ['Sensu_rabbitmq_config[host.domain.com]', 'Sensu_client_config[host.domain.com]']
) }
end

context 'setting params' do
let(:facts) { { :fqdn => 'host.domain.com' } }
let(:params) { {
:rabbitmq_password => 'asdfjkl',
:rabbitmq_ssl_private_key => '/etc/sensu/ssl/key.pem',
:rabbitmq_ssl_cert_chain => '/etc/sensu/ssl/chain.pem',
:rabbitmq_port => '1234',
:rabbitmq_host => 'rabbithost',
:rabbitmq_user => 'sensuuser',
:rabbitmq_vhost => '/myvhost',
:address => '1.2.3.4',
:subscriptions => ['all']
} }

it { should include_class('sensu::package') }
it { should contain_sensu__rabbitmq('client').with(
'ssl_cert_chain' => '/etc/sensu/ssl/chain.pem',
'ssl_private_key' => '/etc/sensu/ssl/key.pem',
'port' => '1234',
'host' => 'rabbithost',
'user' => 'sensuuser',
'vhost' => '/myvhost',
'password' => 'asdfjkl'
) }

it { should contain_sensu_client_config('host.domain.com').with(
'client_name' => 'myclient',
'address' => '1.2.3.4',
'subscriptions' => ['all']
) }

it { should contain_service('sensu-client').with(
'ensure' => 'running',
'enable' => true,
'hasrestart' => true,
'require' => ['Sensu_rabbitmq_config[host.domain.com]', 'Sensu_client_config[host.domain.com]']
) }
end

end
12 changes: 12 additions & 0 deletions spec/defines/sensu_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe 'sensu::handler', :type => :define do
let(:title) { 'myhandler' }
let(:params) { { :type => 'pipe', :command => '/etc/sensu/mycommand.rb' } }

it { should contain_sensu_handler_config('myhandler').with(
'type' => 'pipe',
'command' => '/etc/sensu/mycommand.rb',
'before' => 'Service[sensu-server]'
) }
end
80 changes: 80 additions & 0 deletions spec/defines/sensu_rabbitmq_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper'

describe 'sensu::rabbitmq', :type => :define do
let(:title) { 'myrabbit' }
let(:facts) { { :fqdn => 'hostname.domain.com' } }

let(:params) { {
:ssl_cert_chain => '/etc/sensu/ssl/chain.pem',
:ssl_private_key => '/etc/sensu/ssl/key.pem',
:port => '1234',
:host => 'myhost',
:user => 'sensuuser',
:password => 'sensupass',
:vhost => '/myvhost'
} }

pending "it should test cert installs" do
# if $ssl_cert_chain != '' {
# file { '/etc/sensu/ssl':
# ensure => directory,
# owner => 'sensu',
# group => 'sensu',
# mode => '0755',
# require => Package['sensu'],
# }
#
# if $ssl_cert_chain =~ /^puppet:\/\// {
# file { '/etc/sensu/ssl/cert.pem':
# ensure => present,
# source => $ssl_cert_chain,
# owner => 'sensu',
# group => 'sensu',
# mode => '0444',
# require => File['/etc/sensu/ssl'],
# before => Sensu_rabbitmq_config[$::fqdn],
# }
#
# Sensu_rabbitmq_config {
# ssl_cert_chain => '/etc/sensu/ssl/cert.pem',
# }
# } else {
# Sensu_rabbitmq_config {
# ssl_cert_chain => $ssl_cert_chain,
# }
# }
#
# if $ssl_private_key =~ /^puppet:\/\// {
# file { '/etc/sensu/ssl/key.pem':
# ensure => present,
# source => $ssl_private_key,
# owner => 'sensu',
# group => 'sensu',
# mode => '0440',
# require => File['/etc/sensu/ssl'],
# before => Sensu_rabbitmq_config[$::fqdn],
# }
# Sensu_rabbitmq_config {
# ssl_private_key => '/etc/sensu/ssl/key.pem',
# }
# } else {
# Sensu_rabbitmq_config {
# ssl_private_key => $ssl_private_key,
# }
# }
end

it { should contain_sensu_rabbitmq_config('hostname.domain.com').with(
'port' => '1234',
'host' => 'myhost',
'user' => 'sensuuser',
'password' => 'sensupass',
'vhost' => '/myvhost'
) }

end





Loading

0 comments on commit f4dd39f

Please sign in to comment.