Skip to content

Commit

Permalink
nagios_common: basic spec for contacts.cfg
Browse files Browse the repository at this point in the history
Partially cover the fix in 0e144ab

Change-Id: I6e7402133fb43f06be6ae2742615a046249aa318
  • Loading branch information
hashar authored and akosiaris committed Jun 8, 2017
1 parent 81a3503 commit aee079f
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/nagios_common/.fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixtures:
symlinks:
nagios_common: "#{source_dir}"
2 changes: 2 additions & 0 deletions modules/nagios_common/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format doc
--color
1 change: 1 addition & 0 deletions modules/nagios_common/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'puppetlabs_spec_helper/rake_tasks'
1 change: 1 addition & 0 deletions modules/nagios_common/spec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/fixtures
104 changes: 104 additions & 0 deletions modules/nagios_common/spec/classes/contacts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require 'spec_helper'

describe 'nagios_common::contacts' do

it { is_expected.to compile }

context 'with a dummy contact' do
let(:params) { {
:contacts => [
{
'name' => 'John Dummy',
}
],
} }
it 'should have have a contact name' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/contact_name\s+John Dummy$/)
end
it 'should not have an email set' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.without_content(/^\s+email\s+/)
end
it 'should be notified 24x7' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_period\s+24x7$/)
.with_content(/service_notification_period\s+24x7$/)
end
end

context 'with a contact having a notification period of business-hours' do
let(:params) { {
:contacts => [
{
'name' => 'John Dummy',
'period' => 'business-hours',
}
],
} }
it 'should only be notified during business hours' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_period\s+business-hours$/)
.with_content(/service_notification_period\s+business-hours$/)
end
end

context 'with a contact having an email defined' do
let(:params) { {
:contacts => [
{
'name' => 'John Dummy',
'email' => '[email protected]',
}
],
} }

it 'should have an email set' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/^\s+email\s[email protected]$/)
end
it 'should be notified 24x7' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_period\s+24x7$/)
.with_content(/service_notification_period\s+24x7$/)
end
it 'should be notified by email' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_commands\s+host-notify-by-email$/)
.with_content(/service_notification_commands\s+host-notify-by-email$/)
end
end

context 'with a contact having a single command' do
let(:params) { {
:contacts => [
{
'name' => 'John Dummy',
'commands' => ['singlecmd'],
}
],
} }
it "should be notified by the single command" do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_commands\s+host-notify-singlecmd$/)
.with_content(/service_notification_commands\s+host-notify-singlecmd$/)
end
end

context 'with a contact having multiple commands' do
let(:params) { {
:contacts => [
{
'name' => 'John Dummy',
'commands' => ['cmdone', 'cmdtwo'],
}
],
} }
it 'should be notified by multiple commands' do
is_expected.to contain_file('/etc/icinga/contacts.cfg')
.with_content(/host_notification_commands\s+host-notify-cmdone,host-notify-cmdtwo$/)
.with_content(/service_notification_commands\s+host-notify-cmdone,host-notify-cmdtwo$/)
end
end

end
8 changes: 8 additions & 0 deletions modules/nagios_common/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rspec-puppet/spec_helper'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
end

0 comments on commit aee079f

Please sign in to comment.