File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ def initialize
8
8
end
9
9
10
10
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
12
16
end
13
17
14
18
def clear
Original file line number Diff line number Diff line change 10
10
'int_fact' => 3 ,
11
11
'true_fact' => true ,
12
12
'false_fact' => false ,
13
+ 'os' => { 'name' => 'my_os' , 'release' => { 'major' => '42' } }
13
14
}
14
15
end
15
16
19
20
facter_impl . add ( :int_fact ) { setcode { 3 } }
20
21
facter_impl . add ( :true_fact ) { setcode { true } }
21
22
facter_impl . add ( :false_fact ) { setcode { false } }
23
+ facter_impl . add ( :os ) { setcode { { 'name' => 'my_os' , 'release' => { 'major' => '42' } } } }
22
24
end
23
25
24
26
describe 'noop methods' do
49
51
it 'retrieves a fact of type FalseClass' do
50
52
expect ( facter_impl . value ( :false_fact ) ) . to eq ( false )
51
53
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
52
76
end
53
77
54
78
describe '#to_hash' do
You can’t perform that action at this time.
0 commit comments