Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(FACT-2499) Add test to check that each fact is loaded only once, eve…
Browse files Browse the repository at this point in the history
…n if it is requested by multiple searched facts.
  • Loading branch information
Bogdan Irimie committed Apr 1, 2020
1 parent 93648eb commit f157632
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions spec/framework/core/fact/internal/internal_fact_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

describe Facter::InternalFactManager do
let(:internal_fact_manager) { Facter::InternalFactManager.new }
let(:os_name_class_spy) { class_spy(Facts::Debian::Os::Name) }
let(:os_name_instance_spy) { instance_spy(Facts::Debian::Os::Name) }

describe '#resolve_facts' do
it 'resolved one core fact' do
os_name_class_spy = class_spy(Facts::Debian::Os::Name)
os_name_instance_spy = instance_spy(Facts::Debian::Os::Name)

resolved_fact = mock_resolved_fact('os', 'Ubuntu', nil, [])

allow(os_name_class_spy).to receive(:new).and_return(os_name_instance_spy)
Expand All @@ -14,8 +15,7 @@
searched_fact = instance_spy(Facter::SearchedFact, name: 'os', fact_class: os_name_class_spy, filter_tokens: [],
user_query: '', type: :core)

core_fact_manager = Facter::InternalFactManager.new
resolved_facts = core_fact_manager.resolve_facts([searched_fact])
resolved_facts = internal_fact_manager.resolve_facts([searched_fact])

expect(resolved_facts).to eq([resolved_fact])
end
Expand All @@ -32,10 +32,31 @@
searched_fact = instance_spy(Facter::SearchedFact, name: 'network_.*', fact_class: networking_interface_class_spy,
filter_tokens: [], user_query: '', type: :core)

core_fact_manager = Facter::InternalFactManager.new
resolved_facts = core_fact_manager.resolve_facts([searched_fact])
resolved_facts = internal_fact_manager.resolve_facts([searched_fact])

expect(resolved_facts).to eq([resolved_fact])
end

context 'when there are multiple search facts pointing to the same fact' do
before do
resolved_fact = mock_resolved_fact('os', 'Ubuntu', nil, [])

allow(os_name_class_spy).to receive(:new).and_return(os_name_instance_spy)
allow(os_name_instance_spy).to receive(:call_the_resolver).and_return(resolved_fact)

searched_fact = instance_spy(Facter::SearchedFact, name: 'os.name', fact_class: os_name_class_spy,
filter_tokens: [], user_query: '', type: :core)

searched_fact_with_alias = instance_spy(Facter::SearchedFact, name: 'operatingsystem',
fact_class: os_name_class_spy, filter_tokens: [],
user_query: '', type: :core)

internal_fact_manager.resolve_facts([searched_fact, searched_fact_with_alias])
end

it 'resolves the fact only once' do
expect(os_name_instance_spy).to have_received(:call_the_resolver).once
end
end
end
end

0 comments on commit f157632

Please sign in to comment.