source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/spec/acceptance/loadyaml_spec.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

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