Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FACT-2850) Don't show nil custom facts #2173

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def to_user_output(cli_options, *args)

status = error_check(resolved_facts)

[fact_formatter.format(resolved_facts), status || 0]
[fact_formatter.format(resolved_facts), status]
end

# Logs an exception and an optional message
Expand Down Expand Up @@ -504,14 +504,13 @@ def resolve_fact(user_query)
#
# @api private
def error_check(resolved_facts)
status = 0
if Options[:strict]
missing_names = resolved_facts.select { |fact| fact.type == :nil }.map(&:user_query)

if missing_names.count.positive?
status = 1
log_errors(missing_names)
else
status = nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/facter/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 %i[core legacy].include?(fact.type) && fact.value.nil?
next if %i[custom core legacy].include?(fact.type) && fact.value.nil?

bury_fact(fact)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/facter/model/fact_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
let(:fact_value) { nil }
let(:type) { :custom }

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

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