Hashar has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/331490 )

Change subject: nagios_common: basic spec for contacts.cfg
......................................................................

nagios_common: basic spec for contacts.cfg

Partially cover the fix in 0e144abf44

Change-Id: I6e7402133fb43f06be6ae2742615a046249aa318
---
A modules/nagios_common/.rspec
A modules/nagios_common/Rakefile
A modules/nagios_common/spec/classes/contacts_spec.rb
A modules/nagios_common/spec/fixtures/manifests/site.pp
A modules/nagios_common/spec/fixtures/modules/nagios_common/files
A modules/nagios_common/spec/fixtures/modules/nagios_common/manifests
A modules/nagios_common/spec/fixtures/modules/nagios_common/templates
A modules/nagios_common/spec/spec_helper.rb
8 files changed, 126 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/90/331490/1

diff --git a/modules/nagios_common/.rspec b/modules/nagios_common/.rspec
new file mode 100644
index 0000000..f449dae
--- /dev/null
+++ b/modules/nagios_common/.rspec
@@ -0,0 +1,2 @@
+--format doc
+--color
diff --git a/modules/nagios_common/Rakefile b/modules/nagios_common/Rakefile
new file mode 100644
index 0000000..b6b1144
--- /dev/null
+++ b/modules/nagios_common/Rakefile
@@ -0,0 +1,11 @@
+require 'rspec-puppet/rake_task'
+
+begin
+  if Gem::Specification::find_by_name('puppet-lint')
+    require 'puppet-lint/tasks/puppet-lint'
+    PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"]
+    task :default => [:rspec, :lint]
+  end
+rescue Gem::LoadError
+  task :default => :rspec
+end
diff --git a/modules/nagios_common/spec/classes/contacts_spec.rb 
b/modules/nagios_common/spec/classes/contacts_spec.rb
new file mode 100644
index 0000000..b263a47
--- /dev/null
+++ b/modules/nagios_common/spec/classes/contacts_spec.rb
@@ -0,0 +1,102 @@
+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 {
+                       is_expected.to contain_file('/etc/icinga/contacts.cfg')
+                .with_content(/contact_name\s+John Dummy$/)
+                .without_content(/^\s+email\s+/)
+               }
+       end
+
+    context 'with a contact having a notification period defined' do
+               let(:params) { {
+                       :contacts => [
+                               {
+                                       'name' => 'John Dummy',
+                    'period' => 'business-hours',
+                               }
+                       ],
+               } }
+               it {
+                       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
+
+    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\[email protected]$/)
+        end
+        it "should have host notification period 24x7" do
+            is_expected.to contain_file('/etc/icinga/contacts.cfg')
+                .with_content(/host_notification_period\s+24x7$/)
+        end
+        it "should have service notification period 24x7" do
+            is_expected.to contain_file('/etc/icinga/contacts.cfg')
+                .with_content(/service_notification_period\s+24x7$/)
+        end
+        it "should have notification command host-notify-by-email" do
+            is_expected.to contain_file('/etc/icinga/contacts.cfg')
+                
.with_content(/host_notification_commands\s+host-notify-by-email$/)
+        end
+        it "shoud have service noticiation command host-notify-by-email" do
+            is_expected.to contain_file('/etc/icinga/contacts.cfg')
+                
.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 {
+                       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
+
+    context 'with a contact having multiple commands' do
+               let(:params) { {
+                       :contacts => [
+                               {
+                                       'name' => 'John Dummy',
+                    'commands' => ['cmdone', 'cmdtwo'],
+                               }
+                       ],
+               } }
+               it {
+                       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
diff --git a/modules/nagios_common/spec/fixtures/manifests/site.pp 
b/modules/nagios_common/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/nagios_common/spec/fixtures/manifests/site.pp
diff --git a/modules/nagios_common/spec/fixtures/modules/nagios_common/files 
b/modules/nagios_common/spec/fixtures/modules/nagios_common/files
new file mode 120000
index 0000000..84dafe8
--- /dev/null
+++ b/modules/nagios_common/spec/fixtures/modules/nagios_common/files
@@ -0,0 +1 @@
+../../../../files
\ No newline at end of file
diff --git 
a/modules/nagios_common/spec/fixtures/modules/nagios_common/manifests 
b/modules/nagios_common/spec/fixtures/modules/nagios_common/manifests
new file mode 120000
index 0000000..373b992
--- /dev/null
+++ b/modules/nagios_common/spec/fixtures/modules/nagios_common/manifests
@@ -0,0 +1 @@
+../../../../manifests
\ No newline at end of file
diff --git 
a/modules/nagios_common/spec/fixtures/modules/nagios_common/templates 
b/modules/nagios_common/spec/fixtures/modules/nagios_common/templates
new file mode 120000
index 0000000..f8a06d1
--- /dev/null
+++ b/modules/nagios_common/spec/fixtures/modules/nagios_common/templates
@@ -0,0 +1 @@
+../../../../templates
\ No newline at end of file
diff --git a/modules/nagios_common/spec/spec_helper.rb 
b/modules/nagios_common/spec/spec_helper.rb
new file mode 100644
index 0000000..3a79b20
--- /dev/null
+++ b/modules/nagios_common/spec/spec_helper.rb
@@ -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

-- 
To view, visit https://gerrit.wikimedia.org/r/331490
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e7402133fb43f06be6ae2742615a046249aa318
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to