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