diff options
author | Dmitry Ilyin <dilyin@mirantis.com> | 2016-04-26 21:51:43 +0300 |
---|---|---|
committer | Dmitry Ilyin <dilyin@mirantis.com> | 2016-04-26 21:58:29 +0300 |
commit | 870a272cee6889934d60c4bfd7a814bcf47011f1 (patch) | |
tree | 4450edb42afb65d84ffe57a440747f56d4dbbfda /spec/acceptance/loadyaml_spec.rb | |
parent | b63849c7865e4191e9df5a7651c16c072facee3d (diff) |
Add the default value to the "loadyaml" function
This value will be returned if the is no file
to load or a file could not be parsed.
It's similar to the "parseyaml" function's
default value.
Add the "loadjson" function too
Diffstat (limited to 'spec/acceptance/loadyaml_spec.rb')
-rw-r--r-- | spec/acceptance/loadyaml_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/acceptance/loadyaml_spec.rb b/spec/acceptance/loadyaml_spec.rb index 1e910a9..ba3f0b7 100644 --- a/spec/acceptance/loadyaml_spec.rb +++ b/spec/acceptance/loadyaml_spec.rb @@ -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' |