File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ def initialize
88 end
99
1010 def value ( fact_name )
11- @facts [ fact_name . to_s ]
11+ begin
12+ @facts . dig ( *fact_name . to_s . split ( '.' ) )
13+ rescue TypeError
14+ nil
15+ end
1216 end
1317
1418 def clear
Original file line number Diff line number Diff line change 1010 'int_fact' => 3 ,
1111 'true_fact' => true ,
1212 'false_fact' => false ,
13+ 'os' => { 'name' => 'my_os' , 'release' => { 'major' => '42' } }
1314 }
1415 end
1516
1920 facter_impl . add ( :int_fact ) { setcode { 3 } }
2021 facter_impl . add ( :true_fact ) { setcode { true } }
2122 facter_impl . add ( :false_fact ) { setcode { false } }
23+ facter_impl . add ( :os ) { setcode { { 'name' => 'my_os' , 'release' => { 'major' => '42' } } } }
2224 end
2325
2426 describe 'noop methods' do
4951 it 'retrieves a fact of type FalseClass' do
5052 expect ( facter_impl . value ( :false_fact ) ) . to eq ( false )
5153 end
54+
55+ context 'when using dot-notation' do
56+ it 'retrieves a child fact using dot-notation' do
57+ expect ( facter_impl . value ( 'os.name' ) ) . to eq ( 'my_os' )
58+ end
59+
60+ it 'retrieves a hash child fact using dot-notation' do
61+ expect ( facter_impl . value ( 'os.release' ) ) . to eq ( { 'major' => '42' } )
62+ end
63+
64+ it 'retrieves a deeply nested child fact using dot-notation' do
65+ expect ( facter_impl . value ( 'os.release.major' ) ) . to eq ( '42' )
66+ end
67+
68+ it 'returns nil if a child fact is missing' do
69+ expect ( facter_impl . value ( 'os.release.unknown_subkey' ) ) . to eq ( nil )
70+ end
71+
72+ it 'returns nil if trying to lookup into a string' do
73+ expect ( facter_impl . value ( 'os.name.foo' ) ) . to eq ( nil )
74+ end
75+ end
5276 end
5377
5478 describe '#to_hash' do
You can’t perform that action at this time.
0 commit comments