source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/spec/acceptance/loadjson_spec.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 1.9 KB
Line 
1#! /usr/bin/env ruby -S rspec
2require 'spec_helper_acceptance'
3
4tmpdir = default.tmpdir('stdlib')
5
6describe 'loadjson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
7 describe 'success' do
8 it 'loadjsons array of values' do
9 shell("echo '{\"aaa\":1,\"bbb\":2,\"ccc\":3,\"ddd\":4}' > #{tmpdir}/testjson.json")
10 pp = <<-EOS
11 $o = loadjson('#{tmpdir}/testjson.json')
12 notice(inline_template('loadjson[aaa] is <%= @o["aaa"].inspect %>'))
13 notice(inline_template('loadjson[bbb] is <%= @o["bbb"].inspect %>'))
14 notice(inline_template('loadjson[ccc] is <%= @o["ccc"].inspect %>'))
15 notice(inline_template('loadjson[ddd] is <%= @o["ddd"].inspect %>'))
16 EOS
17
18 apply_manifest(pp, :catch_failures => true) do |r|
19 expect(r.stdout).to match(/loadjson\[aaa\] is 1/)
20 expect(r.stdout).to match(/loadjson\[bbb\] is 2/)
21 expect(r.stdout).to match(/loadjson\[ccc\] is 3/)
22 expect(r.stdout).to match(/loadjson\[ddd\] is 4/)
23 end
24 end
25
26 it 'returns the default value if there is no file to load' do
27 pp = <<-EOS
28 $o = loadjson('#{tmpdir}/no-file.json', {'default' => 'value'})
29 notice(inline_template('loadjson[default] is <%= @o["default"].inspect %>'))
30 EOS
31
32 apply_manifest(pp, :catch_failures => true) do |r|
33 expect(r.stdout).to match(/loadjson\[default\] is "value"/)
34 end
35 end
36
37 it 'returns the default value if the file was parsed with an error' do
38 shell("echo '!' > #{tmpdir}/testjson.json")
39 pp = <<-EOS
40 $o = loadjson('#{tmpdir}/testjson.json', {'default' => 'value'})
41 notice(inline_template('loadjson[default] is <%= @o["default"].inspect %>'))
42 EOS
43
44 apply_manifest(pp, :catch_failures => true) do |r|
45 expect(r.stdout).to match(/loadjson\[default\] is "value"/)
46 end
47 end
48 end
49 describe 'failure' do
50 it 'fails with no arguments'
51 end
52end
Note: See TracBrowser for help on using the repository browser.