|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe Facts::Linux::Hypervisors::HyperV do |
| 4 | + describe '#call_the_resolver' do |
| 5 | + subject(:fact) { Facts::Linux::Hypervisors::HyperV.new } |
| 6 | + |
| 7 | + before do |
| 8 | + allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:sys_vendor).and_return(manufacturer) |
| 9 | + allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(product_name) |
| 10 | + end |
| 11 | + |
| 12 | + context 'when resolver returns hyper_v' do |
| 13 | + let(:manufacturer) { 'Microsoft' } |
| 14 | + let(:product_name) { 'Virtual Machine' } |
| 15 | + let(:value) { {} } |
| 16 | + |
| 17 | + it 'calls Facter::Resolvers::DMIBios with :sys_vendor' do |
| 18 | + fact.call_the_resolver |
| 19 | + expect(Facter::Resolvers::Linux::DmiBios).to have_received(:resolve).with(:sys_vendor) |
| 20 | + end |
| 21 | + |
| 22 | + it 'calls Facter::Resolvers::DMIBios with :product_name' do |
| 23 | + fact.call_the_resolver |
| 24 | + expect(Facter::Resolvers::Linux::DmiBios).to have_received(:resolve).with(:product_name) |
| 25 | + end |
| 26 | + |
| 27 | + it 'returns hyper_v fact' do |
| 28 | + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ |
| 29 | + have_attributes(name: 'hypervisors.hyperv', value: value) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'when resolver returns nil' do |
| 34 | + let(:manufacturer) { nil } |
| 35 | + let(:product_name) { nil } |
| 36 | + let(:value) { nil } |
| 37 | + |
| 38 | + it 'returns virtual fact as nil' do |
| 39 | + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ |
| 40 | + have_attributes(name: 'hypervisors.hyperv', value: value) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + context 'when manufacturer is not Microsoft, but product name is Virtual Machine' do |
| 45 | + let(:manufacturer) { 'unknown' } |
| 46 | + let(:product_name) { 'Virtual Machine' } |
| 47 | + let(:value) { {} } |
| 48 | + |
| 49 | + it 'returns hyper-v fact' do |
| 50 | + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ |
| 51 | + have_attributes(name: 'hypervisors.hyperv', value: value) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context 'when manufacturer is Microsoft and product name is not Virtual Machine' do |
| 56 | + let(:manufacturer) { 'Microsoft' } |
| 57 | + let(:product_name) { 'something_else' } |
| 58 | + let(:value) { {} } |
| 59 | + |
| 60 | + it 'returns hyper-v fact' do |
| 61 | + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ |
| 62 | + have_attributes(name: 'hypervisors.hyperv', value: value) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments