2014-05-07 03:48:59 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
|
|
|
require 'spec_helper_acceptance'
|
|
|
|
|
2014-06-24 00:13:29 +02:00
|
|
|
tmpdir = default.tmpdir('stdlib')
|
|
|
|
|
2014-05-07 03:48:59 +02:00
|
|
|
describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
|
|
|
describe 'success' do
|
|
|
|
it 'loadyamls array of values' do
|
2014-06-24 00:13:29 +02:00
|
|
|
shell("echo '---
|
2014-05-07 03:48:59 +02:00
|
|
|
aaa: 1
|
|
|
|
bbb: 2
|
|
|
|
ccc: 3
|
2014-06-24 00:13:29 +02:00
|
|
|
ddd: 4' > #{tmpdir}/testyaml.yaml")
|
2014-05-07 03:48:59 +02:00
|
|
|
pp = <<-EOS
|
2014-06-24 00:13:29 +02:00
|
|
|
$o = loadyaml('#{tmpdir}/testyaml.yaml')
|
2014-05-07 03:48:59 +02:00
|
|
|
notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>'))
|
|
|
|
notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>'))
|
|
|
|
notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>'))
|
|
|
|
notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>'))
|
|
|
|
EOS
|
|
|
|
|
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
|
|
|
expect(r.stdout).to match(/loadyaml\[aaa\] is 1/)
|
|
|
|
expect(r.stdout).to match(/loadyaml\[bbb\] is 2/)
|
|
|
|
expect(r.stdout).to match(/loadyaml\[ccc\] is 3/)
|
|
|
|
expect(r.stdout).to match(/loadyaml\[ddd\] is 4/)
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 20:51:43 +02:00
|
|
|
|
|
|
|
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
|
2014-05-07 03:48:59 +02:00
|
|
|
end
|
|
|
|
describe 'failure' do
|
|
|
|
it 'fails with no arguments'
|
|
|
|
end
|
|
|
|
end
|