Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / loadyaml_spec.rb
1 require 'spec_helper_acceptance'
2
3 tmpdir = default.tmpdir('stdlib')
4
5 describe 'loadyaml function' do
6   describe 'success' do
7     shell("echo '---
8       aaa: 1
9       bbb: 2
10       ccc: 3
11       ddd: 4' > #{tmpdir}/test1yaml.yaml")
12     pp1 = <<-DOC
13       $o = loadyaml('#{tmpdir}/test1yaml.yaml')
14       notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>'))
15       notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>'))
16       notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>'))
17       notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>'))
18     DOC
19     regex_array = [%r{loadyaml\[aaa\] is 1}, %r{loadyaml\[bbb\] is 2}, %r{loadyaml\[ccc\] is 3}, %r{loadyaml\[ddd\] is 4}]
20     it 'loadyamls array of values' do
21       apply_manifest(pp1, :catch_failures => true) do |r|
22         regex_array.each do |i|
23           expect(r.stdout).to match(i)
24         end
25       end
26     end
27
28     pp2 = <<-DOC
29       $o = loadyaml('#{tmpdir}/no-file.yaml', {'default' => 'value'})
30       notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
31     DOC
32     it 'returns the default value if there is no file to load' do
33       apply_manifest(pp2, :catch_failures => true) do |r|
34         expect(r.stdout).to match(%r{loadyaml\[default\] is "value"})
35       end
36     end
37
38     shell("echo '!' > #{tmpdir}/test2yaml.yaml")
39     pp3 = <<-DOC
40       $o = loadyaml('#{tmpdir}/test2yaml.yaml', {'default' => 'value'})
41       notice(inline_template('loadyaml[default] is <%= @o["default"].inspect %>'))
42     DOC
43     it 'returns the default value if the file was parsed with an error' do
44       apply_manifest(pp3, :catch_failures => true) do |r|
45         expect(r.stdout).to match(%r{loadyaml\[default\] is "value"})
46       end
47     end
48   end
49   describe 'failure' do
50     it 'fails with no arguments'
51   end
52 end