Mercurial > repos > other > Puppet
annotate modules/stdlib/spec/functions/try_get_value_spec.rb @ 320:99e3ca448d55
Fix Remi PHP on CentOS 8
It uses the new "modules" approach, so we need to use a new
package provider
They also use different signing keys
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 Mar 2020 10:58:00 +0000 |
parents | d9352a684e62 |
children |
rev | line source |
---|---|
272 | 1 require 'spec_helper' |
2 | |
3 describe 'try_get_value' do | |
4 let(:data) do | |
5 { | |
6 'a' => { | |
7 'g' => '2', | |
8 'e' => [ | |
9 'f0', | |
10 'f1', | |
11 { | |
12 'x' => { | |
13 'y' => 'z', | |
14 }, | |
15 }, | |
16 'f3', | |
17 ], | |
18 }, | |
19 'b' => true, | |
20 'c' => false, | |
21 'd' => '1', | |
22 } | |
23 end | |
24 | |
25 context 'with single values' do | |
26 it 'exists' do | |
27 is_expected.not_to eq(nil) | |
28 end | |
29 | |
30 it 'is able to return a single value' do | |
31 is_expected.to run.with_params('test').and_return('test') | |
32 end | |
33 | |
34 it 'uses the default value if data is a single value and path is present' do | |
35 is_expected.to run.with_params('test', 'path', 'default').and_return('default') | |
36 end | |
37 | |
38 it 'returns default if there is no data' do | |
39 is_expected.to run.with_params(nil, nil, 'default').and_return('default') | |
40 end | |
41 | |
42 it 'is able to use data structures as default values' do | |
43 is_expected.to run.with_params('test', 'path', data).and_return(data) | |
44 end | |
45 end | |
46 | |
47 context 'with structure values' do | |
48 it 'is able to extracts a single hash value' do | |
49 is_expected.to run.with_params(data, 'd', 'default').and_return('1') | |
50 end | |
51 | |
52 it 'is able to extract a deeply nested hash value' do | |
53 is_expected.to run.with_params(data, 'a/g', 'default').and_return('2') | |
54 end | |
55 | |
56 it 'returns the default value if the path is not found' do | |
57 is_expected.to run.with_params(data, 'missing', 'default').and_return('default') | |
58 end | |
59 | |
60 it 'returns the default value if the path is too long' do | |
61 is_expected.to run.with_params(data, 'a/g/c/d', 'default').and_return('default') | |
62 end | |
63 | |
64 it 'supports an array index in the path' do | |
65 is_expected.to run.with_params(data, 'a/e/1', 'default').and_return('f1') | |
66 end | |
67 | |
68 it 'returns the default value if an array index is not a number' do | |
69 is_expected.to run.with_params(data, 'a/b/c', 'default').and_return('default') | |
70 end | |
71 | |
72 it 'returns the default value if and index is out of array length' do | |
73 is_expected.to run.with_params(data, 'a/e/5', 'default').and_return('default') | |
74 end | |
75 | |
76 it 'is able to path though both arrays and hashes' do | |
77 is_expected.to run.with_params(data, 'a/e/2/x/y', 'default').and_return('z') | |
78 end | |
79 | |
80 it 'is able to return "true" value: default' do | |
81 is_expected.to run.with_params(data, 'b', 'default').and_return(true) | |
82 end | |
83 | |
84 it 'is able to return "true" value' do | |
85 is_expected.to run.with_params(data, 'm', true).and_return(true) | |
86 end | |
87 | |
88 it 'is able to return "false" value: default' do | |
89 is_expected.to run.with_params(data, 'c', 'default').and_return(false) | |
90 end | |
91 | |
92 it 'is able to return "false" value' do | |
93 is_expected.to run.with_params(data, 'm', false).and_return(false) | |
94 end | |
95 | |
96 it 'returns "nil" if value is not found and no default value is provided' do | |
97 is_expected.to run.with_params(data, 'a/1').and_return(nil) | |
98 end | |
99 | |
100 it 'is able to use a custom path separator' do | |
101 is_expected.to run.with_params(data, 'a::g', 'default', '::').and_return('2') | |
102 end | |
103 | |
104 it 'is able to use a custom path separator: default' do | |
105 is_expected.to run.with_params(data, 'a::c', 'default', '::').and_return('default') | |
106 end | |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
107 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
108 it 'is able to throw an error with incorrect params' do |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
109 is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Wrong number of arguments}i) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
110 end |
272 | 111 end |
112 end |