Skip to content

Commit

Permalink
(FACT-2317) Add Facter.define_fact method
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Tanasoiu committed Sep 22, 2020
1 parent fa574e9 commit cfe62e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ def debugonce(message)
nil
end

# Define a new fact or extend an existing fact.
#
# @param name [Symbol] The name of the fact to define
# @param options [Hash] A hash of options to set on the fact
#
# @return [Facter::Util::Fact] The fact that was defined
#
# @api public
def define_fact(name, options = {}, &block)
options[:fact_type] = :custom
LegacyFacter.define_fact(name, options, &block)
end

def on_message(&block)
Facter::Log.on_message(&block)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/facter/facter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ def mock_collection(method, os_name = nil, error = nil)
end
end

describe '#define_fact' do
it 'sends call to LegacyFacter' do
allow(LegacyFacter).to receive(:define_fact)

Facter.define_fact('fact_name') {}

expect(LegacyFacter).to have_received(:define_fact).once.with('fact_name', { fact_type: :custom })
end
end

describe '#trace?' do
it 'returns trace variable' do
expect(Facter).not_to be_trace
Expand Down

0 comments on commit cfe62e4

Please sign in to comment.