This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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,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 |