From cd0090f06dd11bd005dc5c67cacc5db0a30ec99c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Mon, 20 May 2013 14:13:57 +0200
Subject: [PATCH] Various fixes, add spec for init class

---
 manifests/params.pp             |  8 ++++----
 spec/.rspec                     |  6 ++++++
 spec/classes/postfix_spec.rb    | 21 +++++++++++++++++++++
 spec/fixtures/manifests/site.pp |  0
 spec/spec_helper.rb             |  4 ++++
 templates/master.cf.debian.erb  |  8 ++++----
 templates/master.cf.redhat.erb  |  4 ++--
 7 files changed, 41 insertions(+), 10 deletions(-)
 create mode 100644 spec/.rspec
 create mode 100644 spec/classes/postfix_spec.rb
 create mode 100644 spec/fixtures/manifests/site.pp
 create mode 100644 spec/spec_helper.rb

diff --git a/manifests/params.pp b/manifests/params.pp
index 4d00b60..a218848 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,9 +1,9 @@
 class postfix::params {
   case $::osfamily {
     'RedHat': {
-      $seltype = $::lsbmajdistrelease {
-        '4'     => 'etc_t',
-        '5','6' => 'postfix_etc_t',
+      $seltype = $::lsbmajdistrelease ? {
+        '4'   => 'etc_t',
+        /5|6/ => 'postfix_etc_t',
         default => undef,
       }
 
@@ -13,7 +13,7 @@ class postfix::params {
     }
 
     'Debian': {
-      $seltype = undef,
+      $seltype = undef
 
       $mailx_package = $::lsbdistcodename ? {
         /sarge|etch|lenny|lucid/ => 'mailx',
diff --git a/spec/.rspec b/spec/.rspec
new file mode 100644
index 0000000..91cd642
--- /dev/null
+++ b/spec/.rspec
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
diff --git a/spec/classes/postfix_spec.rb b/spec/classes/postfix_spec.rb
new file mode 100644
index 0000000..0ee2119
--- /dev/null
+++ b/spec/classes/postfix_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'postfix' do
+  context 'when on Debian' do
+    let (:facts) { {
+      :operatingsystem => 'Debian',
+      :osfamily        => 'Debian',
+    } }
+
+    it { should contain_package('postfix') }
+  end
+
+  context 'when on RedHat' do
+    let (:facts) { {
+      :operatingsystem => 'RedHat',
+      :osfamily        => 'RedHat',
+    } }
+
+    it { should contain_package('postfix') }
+  end
+end
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..4edc964
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,4 @@
+require 'mocha'
+require 'rspec-puppet'
+require 'puppetlabs_spec_helper/module_spec_helper'
+
diff --git a/templates/master.cf.debian.erb b/templates/master.cf.debian.erb
index 7232a3e..b07b26d 100644
--- a/templates/master.cf.debian.erb
+++ b/templates/master.cf.debian.erb
@@ -8,11 +8,11 @@
 #               (yes)   (yes)   (yes)   (never) (100)
 # ==========================================================================
 <% if has_variable?('postfix_master_smtp') -%>
-<%= postfix_master_smtp %>
-<% elsif postfix_smtp_listen == 'all' -%>
+<%= @postfix_master_smtp %>
+<% elsif scope.lookupvar('postfix::smtp_listen') == 'all' -%>
 smtp      inet  n       -       -       -       -       smtpd
 <% else -%>
-<%= postfix_smtp_listen %>:smtp      inet  n       -       -       -       -       smtpd
+<%= scope.lookupvar('postfix::smtp_listen') %>:smtp      inet  n       -       -       -       -       smtpd
 <% end -%>
 <% if has_variable?('postfix_master_submission') -%>
 <%= postfix_master_submission %>
@@ -68,7 +68,7 @@ scache	  unix	-	-	-	-	1	scache
 # Also specify in main.cf: maildrop_destination_recipient_limit=1
 #
 maildrop  unix  -       n       n       -       -       pipe
-  flags=DRhu user=<%= postfix_mail_user %> argv=/usr/bin/maildrop -d ${recipient}
+  flags=DRhu user=<%= scope.lookupvar('postfix::mail_user') %> argv=/usr/bin/maildrop -d ${recipient}
 #
 # See the Postfix UUCP_README file for configuration details.
 #
diff --git a/templates/master.cf.redhat.erb b/templates/master.cf.redhat.erb
index aaf2483..cfc4c40 100644
--- a/templates/master.cf.redhat.erb
+++ b/templates/master.cf.redhat.erb
@@ -7,10 +7,10 @@
 # service type  private unpriv  chroot  wakeup  maxproc command + args
 #               (yes)   (yes)   (yes)   (never) (100)
 # ==========================================================================
-<% if postfix_smtp_listen == 'all' -%>
+<% if scope.lookupvar('postfix::smtp_listen') == 'all' -%>
 smtp      inet  n       -       n       -       -       smtpd
 <% else -%>
-<%= postfix_smtp_listen %>:smtp      inet  n       -       n       -       -       smtpd
+<%= scope.lookupvar('postfix::smtp_listen') %>:smtp      inet  n       -       n       -       -       smtpd
 <% end -%>
 #smtp      inet  n       -       n       -       -       smtpd
 #submission inet n       -       n       -       -       smtpd
-- 
GitLab