From 17d9d6ee3009fa761a5536f4a68b91df297ccb7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <github+aem1eeshi1@raphink.net>
Date: Tue, 19 Sep 2017 16:34:34 +0200
Subject: [PATCH] Fix resource dependencies (#185)

* Fix resource dependencies

Dependencies must be set only if the resources exist in the catalog.
For some weird reason, this worked in Puppet 4 (and shouldn't have).

* Fix AbsolutePath test for Puppet 5
---
 manifests/transport.pp                 | 14 +++++++++-----
 manifests/virtual.pp                   | 14 +++++++++-----
 spec/defines/postfix_hash_spec.rb      |  2 +-
 spec/defines/postfix_transport_spec.rb |  2 +-
 spec/defines/postfix_virtual_spec.rb   |  2 +-
 5 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/manifests/transport.pp b/manifests/transport.pp
index 09a5202..fa29a58 100644
--- a/manifests/transport.pp
+++ b/manifests/transport.pp
@@ -76,10 +76,14 @@ define postfix::transport (
     lens    => 'Postfix_Transport.lns',
     incl    => $file,
     changes => $changes,
-    require => [
-      Package['postfix'],
-      Augeas::Lens['postfix_transport'],
-      ],
-    notify  => Postfix::Hash['/etc/postfix/transport'],
+    require => Augeas::Lens['postfix_transport'],
+  }
+
+  if defined(Package['postfix']) {
+    Package['postfix'] -> Postfix::Transport[$title]
+  }
+
+  if defined(Postfix::Hash['/etc/postfix/transport']) {
+    Postfix::Transport[$title] ~> Postfix::Hash['/etc/postfix/transport']
   }
 }
diff --git a/manifests/virtual.pp b/manifests/virtual.pp
index 07bab2c..6b43e0c 100644
--- a/manifests/virtual.pp
+++ b/manifests/virtual.pp
@@ -63,10 +63,14 @@ define postfix::virtual (
     incl    => $file,
     lens    => 'Postfix_Virtual.lns',
     changes => $changes,
-    require => [
-      Package['postfix'],
-      Augeas::Lens['postfix_virtual'],
-      ],
-    notify  => Postfix::Hash[$file],
+    require => Augeas::Lens['postfix_virtual'],
+  }
+
+  if defined(Package['postfix']) {
+    Package['postfix'] -> Postfix::Virtual[$title]
+  }
+
+  if defined(Postfix::Hash[$file]) {
+    Postfix::Virtual[$title] ~> Postfix::Hash[$file]
   }
 }
diff --git a/spec/defines/postfix_hash_spec.rb b/spec/defines/postfix_hash_spec.rb
index 6502d89..d6ca670 100644
--- a/spec/defines/postfix_hash_spec.rb
+++ b/spec/defines/postfix_hash_spec.rb
@@ -40,7 +40,7 @@ describe 'postfix::hash' do
         it 'should fail' do
           expect {
             is_expected.to contain_file('/tmp/foo')
-          }.to raise_error(Puppet::Error, /got 'foo'/)
+          }.to raise_error(Puppet::Error, /, got /)
         end
       end
 
diff --git a/spec/defines/postfix_transport_spec.rb b/spec/defines/postfix_transport_spec.rb
index 8e1e31c..e3f2283 100644
--- a/spec/defines/postfix_transport_spec.rb
+++ b/spec/defines/postfix_transport_spec.rb
@@ -63,7 +63,7 @@ describe 'postfix::transport' do
         it 'should fail' do
           expect {
             is_expected.to contain_augeas('Postfix transport - foo')
-          }.to raise_error(Puppet::Error, /got 'baz'/)
+          }.to raise_error(Puppet::Error, /, got /)
         end
       end
 
diff --git a/spec/defines/postfix_virtual_spec.rb b/spec/defines/postfix_virtual_spec.rb
index 86d9b1a..cd6dcfa 100644
--- a/spec/defines/postfix_virtual_spec.rb
+++ b/spec/defines/postfix_virtual_spec.rb
@@ -58,7 +58,7 @@ describe 'postfix::virtual' do
         it 'should fail' do
           expect {
             is_expected.to contain_augeas('Postfix virtual - foo')
-          }.to raise_error(Puppet::Error, /got 'baz'/)
+          }.to raise_error(Puppet::Error, /, got /)
         end
       end
 
-- 
GitLab