This repository was archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
(FACT-2538) Don't save core and legacy facts in collection if they have no value #441
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c3c6b7c
(FACT-2538) Don't save facts in collection if they have nill value.
197c17f
(FACT-2538) Only exclude :core and :legacy facts with nill value. Add…
87e85b9
(FACT-2538) Update condition for rejecting facts.
c98c19f
(FACT-2538) Fix test for custom fact.
4009011
(FACT-2538) Refactor tests.
fa13dff
(FACT-2538) Remove commented line of code.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,69 @@ | ||
| # 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 | ||
| let(:user_query) { 'os' } | ||
| let(:resolved_fact) { Facter::ResolvedFact.new(fact_name, fact_value, type) } | ||
|
|
||
| fact_collection.build_fact_collection!([resolved_fact]) | ||
| expected_hash = { 'os' => { 'version' => fact_value } } | ||
| before do | ||
| resolved_fact.filter_tokens = [] | ||
| resolved_fact.user_query = user_query | ||
| end | ||
|
|
||
| expect(fact_collection).to eq(expected_hash) | ||
| end | ||
| context 'when fact has some value' do | ||
| let(:fact_name) { 'os.version' } | ||
| let(:fact_value) { '1.2.3' } | ||
| let(:type) { :core } | ||
|
|
||
| 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(:fact_name) { 'os.version' } | ||
| let(:fact_value) { nil } | ||
| let(:type) { :legacy } | ||
|
|
||
| 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(:fact_name) { 'os.version' } | ||
| let(:fact_value) { nil } | ||
| let(:type) { :core } | ||
|
|
||
| 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 | ||
|
|
||
| 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' | ||
| context 'when fact type is :custom' do | ||
| let(:fact_name) { 'operatingsystem' } | ||
| let(:fact_value) { nil } | ||
| let(:type) { :custom } | ||
|
|
||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.