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

Commit

Permalink
Merge c98c19f into 0f7cb7a
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie committed Apr 9, 2020
2 parents 0f7cb7a + c98c19f commit a02d5dc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/models/fact_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize

def build_fact_collection!(facts)
facts.each do |fact|
next if fact.type == :core && fact.value.nil?
next if %i[core legacy].include?(fact.type) && fact.value.nil?

bury_fact(fact)
end
Expand Down
81 changes: 63 additions & 18 deletions spec/facter/model/fact_collection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,74 @@
# frozen_string_literal: true

describe Facter::FactCollection do
it 'adds elements to fact collection' do
fact_value = '1.2.3'
subject(:fact_collection) { Facter::FactCollection.new }

fact_collection = Facter::FactCollection.new
resolved_fact = Facter::ResolvedFact.new('os.version', fact_value)
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'os'
describe '#build_fact_collection!' do
context 'when fact has some value' do
let(:fact_value) { '1.2.3' }
let(:resolved_fact) { Facter::ResolvedFact.new('os.version', fact_value, :core) }

fact_collection.build_fact_collection!([resolved_fact])
expected_hash = { 'os' => { 'version' => fact_value } }
before do
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'os'
end

expect(fact_collection).to eq(expected_hash)
end
it 'adds fact to collection' do
fact_collection.build_fact_collection!([resolved_fact])
expected_hash = { 'os' => { 'version' => fact_value } }

expect(fact_collection).to eq(expected_hash)
end
end

context 'when fact value is nil' do
context 'when fact type is legacy' do
let(:resolved_fact) { Facter::ResolvedFact.new('os.version', nil, :legacy) }

before do
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'os'
end

it 'does not add fact to collection' do
fact_collection.build_fact_collection!([resolved_fact])
expected_hash = {}

expect(fact_collection).to eq(expected_hash)
end
end

context 'when fact type is core' do
let(:resolved_fact) { Facter::ResolvedFact.new('os.version', nil, :core) }

before do
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'os'
end

it 'does not add fact to collection' do
fact_collection.build_fact_collection!([resolved_fact])
expected_hash = {}

expect(fact_collection).to eq(expected_hash)
end
end

context 'when fact type is :custom' do
let(:resolved_fact) { Facter::ResolvedFact.new('operatingsystem', nil, :custom) }

it 'does not add elements to fact collection if fact value is nil' do
fact_collection = Facter::FactCollection.new
resolved_fact = Facter::ResolvedFact.new('os.version', nil)
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'os'
before do
resolved_fact.filter_tokens = []
resolved_fact.user_query = 'operatingsystem'
end

fact_collection.build_fact_collection!([resolved_fact])
expected_hash = {}
it 'adds fact to collection' do
fact_collection.build_fact_collection!([resolved_fact])
expected_hash = { 'operatingsystem' => nil }

expect(fact_collection).to eq(expected_hash)
expect(fact_collection).to eq(expected_hash)
end
end
end
end
end

0 comments on commit a02d5dc

Please sign in to comment.