File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ def check_product_name
3535 product_name = Facter ::Resolvers ::Linux ::DmiBios . resolve ( :product_name )
3636 return unless product_name
3737
38- Facter ::FactsUtils ::HYPERVISORS_HASH . each { |key , value | return value if product_name . include? ( key ) }
38+ _ , value = Facter ::FactsUtils ::HYPERVISORS_HASH . find { |key , _value | product_name . include? ( key ) }
39+ value
3940 end
4041
4142 def check_bios_vendor
Original file line number Diff line number Diff line change @@ -33,7 +33,8 @@ def check_product_name
3333 product_name = Facter ::Resolvers ::Linux ::DmiBios . resolve ( :product_name )
3434 return unless product_name
3535
36- Facter ::FactsUtils ::HYPERVISORS_HASH . each { |key , value | return value if product_name . include? ( key ) }
36+ _ , value = Facter ::FactsUtils ::HYPERVISORS_HASH . find { |key , _value | product_name . include? ( key ) }
37+ value
3738 end
3839
3940 def check_bios_vendor
Original file line number Diff line number Diff line change 1313 allow ( Facter ::Resolvers ::Linux ::DmiBios ) . to receive ( :resolve ) . with ( :bios_vendor ) . and_return ( nil )
1414 end
1515
16+ context 'when physical machine with no hypervisor' do
17+ let ( :hypervisor ) { nil }
18+ let ( :value ) { nil }
19+
20+ before do
21+ allow ( Facter ::Resolvers ::Linux ::DmiBios ) . to receive ( :resolve ) . with ( :product_name ) . and_return ( 'MS-7A71' )
22+ end
23+
24+ it 'returns ec2 metadata fact as nil' do
25+ expect ( fact . call_the_resolver ) . to be_an_instance_of ( Facter ::ResolvedFact ) . and \
26+ have_attributes ( name : 'ec2_metadata' , value : nil )
27+ end
28+
29+ it "doesn't call Ec2 resolver" do
30+ fact . call_the_resolver
31+ expect ( Facter ::Resolvers ::Ec2 ) . not_to have_received ( :resolve ) . with ( :metadata )
32+ end
33+ end
34+
1635 context 'when hypervisor is not kvm or xen' do
1736 let ( :hypervisor ) { nil }
1837 let ( :value ) { nil }
Original file line number Diff line number Diff line change 1313 allow ( Facter ::Resolvers ::Linux ::DmiBios ) . to receive ( :resolve ) . with ( :bios_vendor ) . and_return ( nil )
1414 end
1515
16+ context 'when physical machine with no hypervisor' do
17+ let ( :hypervisor ) { nil }
18+ let ( :value ) { nil }
19+
20+ before do
21+ allow ( Facter ::Resolvers ::Linux ::DmiBios ) . to receive ( :resolve ) . with ( :product_name ) . and_return ( 'MS-7A71' )
22+ end
23+
24+ it 'returns ec2 metadata fact as nil' do
25+ expect ( fact . call_the_resolver ) . to be_an_instance_of ( Facter ::ResolvedFact ) . and \
26+ have_attributes ( name : 'ec2_userdata' , value : nil )
27+ end
28+
29+ it "doesn't call Ec2 resolver" do
30+ fact . call_the_resolver
31+ expect ( Facter ::Resolvers ::Ec2 ) . not_to have_received ( :resolve ) . with ( :metadata )
32+ end
33+ end
34+
1635 context 'when hypervisor is not kvm or xen' do
1736 let ( :hypervisor ) { nil }
1837 let ( :value ) { nil }
You can’t perform that action at this time.
0 commit comments