-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nagios_common: basic spec for contacts.cfg
Partially cover the fix in 0e144ab Change-Id: I6e7402133fb43f06be6ae2742615a046249aa318
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fixtures: | ||
symlinks: | ||
nagios_common: "#{source_dir}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--format doc | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'puppetlabs_spec_helper/rake_tasks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |