8
8
# note the type is the :nil symbol
9
9
Facter ::ResolvedFact . new ( 'missing_fact' , nil , :nil , 'missing_fact' )
10
10
end
11
+ let ( :hash_fact ) do
12
+ Facter ::ResolvedFact . new ( 'mountpoints' , { '/boot' => { 'filesystem' => 'ext4' , 'device' => 'dev1' } ,
13
+ '/' => { 'filesystem' => 'ext4' , 'device' => 'dev2' } } ,
14
+ :core , 'mountpoints' )
15
+ end
11
16
12
17
let ( :logger ) { instance_spy ( Facter ::Log ) }
13
18
let ( :config_reader_double ) { class_spy ( Facter ::ConfigReader ) }
14
19
20
+ sorted_fact_hash = { 'mountpoints' => { '/' => { 'device' => 'dev2' , 'filesystem' => 'ext4' } ,
21
+ '/boot' => { 'device' => 'dev1' , 'filesystem' => 'ext4' } } }
22
+
15
23
before do
16
24
allow ( Facter ::ConfigReader ) . to receive ( :init ) . and_return ( config_reader_double )
17
25
allow ( config_reader_double ) . to receive ( :cli ) . and_return ( nil )
@@ -56,13 +64,32 @@ def stub_no_fact
56
64
expect ( Facter . resolve ( '' ) ) . to be_an_instance_of ( Hash )
57
65
end
58
66
67
+ context 'when user query in arguments' do
68
+ it 'returns a stable order hash' do
69
+ stub_facts ( [ hash_fact ] )
70
+ expect ( Facter . resolve ( 'mountpoints' ) ) . to eq ( sorted_fact_hash )
71
+ end
72
+ end
73
+
59
74
context 'when user query and options in arguments' do
60
75
it 'returns one resolved fact' do
61
76
stub_facts ( [ os_fact ] )
62
77
63
78
expect ( Facter . resolve ( 'os.name --show-legacy' ) ) . to eq ( 'os.name' => 'ubuntu' )
64
79
end
65
80
end
81
+
82
+ context 'when there is no user query' do
83
+ let ( :hash_fact_no_user_query ) do
84
+ Facter ::ResolvedFact . new ( 'mountpoints' , { '/boot' => { 'filesystem' => 'ext4' , 'device' => 'dev1' } ,
85
+ '/' => { 'filesystem' => 'ext4' , 'device' => 'dev2' } } , :core , '' )
86
+ end
87
+
88
+ it 'returns a stable order hash' do
89
+ stub_facts ( [ hash_fact_no_user_query ] )
90
+ expect ( Facter . resolve ( '' ) ) . to eq ( sorted_fact_hash )
91
+ end
92
+ end
66
93
end
67
94
68
95
describe '#to_hash' do
@@ -85,6 +112,11 @@ def stub_no_fact
85
112
expect ( Facter . to_hash ) . to eq ( { } )
86
113
end
87
114
end
115
+
116
+ it 'returns a stable order hash' do
117
+ stub_facts ( [ hash_fact ] )
118
+ expect ( Facter . to_hash ) . to eq ( sorted_fact_hash )
119
+ end
88
120
end
89
121
90
122
describe '#to_user_output' do
0 commit comments