Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / loadyaml_spec.rb
index 1e910a9..57fb8cb 100644 (file)
@@ -3,7 +3,7 @@ require 'spec_helper_acceptance'
 
 tmpdir = default.tmpdir('stdlib')
 
-describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+describe 'loadyaml function' do
   describe 'success' do
     it 'loadyamls array of values' do
       shell("echo '---
@@ -26,6 +26,29 @@ describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
         expect(r.stdout).to match(/loadyaml\[ddd\] is 4/)
       end
     end
+
+    it 'returns the default value if there is no file to load' do
+      pp = <<-EOS
+      $o = loadyaml('#{tmpdir}/no-file.yaml', {'default' => 'value'})
+      notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
+      EOS
+
+      apply_manifest(pp, :catch_failures => true) do |r|
+        expect(r.stdout).to match(/loadyaml\[default\] is "value"/)
+      end
+    end
+
+    it 'returns the default value if the file was parsed with an error' do
+      shell("echo '!' > #{tmpdir}/testyaml.yaml")
+      pp = <<-EOS
+      $o = loadyaml('#{tmpdir}/testyaml.yaml', {'default' => 'value'})
+      notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
+      EOS
+
+      apply_manifest(pp, :catch_failures => true) do |r|
+        expect(r.stdout).to match(/loadyaml\[default\] is "value"/)
+      end
+    end
   end
   describe 'failure' do
     it 'fails with no arguments'