Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / try_get_value_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'try_get_value function' do
4   describe 'success' do
5     pp1 = <<-DOC
6       $data = {
7         'a' => { 'b' => 'passing'}
8       }
9
10       $tests = try_get_value($data, 'a/b')
11       notice(inline_template('tests are <%= @tests.inspect %>'))
12     DOC
13     it 'gets a value' do
14       apply_manifest(pp1, :catch_failures => true) do |r|
15         expect(r.stdout).to match(%r{tests are "passing"})
16       end
17     end
18   end
19
20   describe 'failure' do
21     pp2 = <<-DOC
22       $data = {
23         'a' => { 'b' => 'passing'}
24       }
25
26       $tests = try_get_value($data, 'c/d', 'using the default value')
27       notice(inline_template('tests are <%= @tests.inspect %>'))
28     DOC
29     it 'uses a default value' do
30       apply_manifest(pp2, :catch_failures => true) do |r|
31         expect(r.stdout).to match(%r{using the default value})
32       end
33     end
34
35     pp = <<-DOC
36       $o = try_get_value()
37     DOC
38     it 'raises error on incorrect number of arguments' do
39       apply_manifest(pp, :expect_failures => true) do |r|
40         expect(r.stderr).to match(%r{wrong number of arguments}i)
41       end
42     end
43   end
44 end