Skip to content

Commit

Permalink
Merge pull request #157 from jordanbreen28/bug-fix_merging_custom_facts
Browse files Browse the repository at this point in the history
Use facterdb_string_keys configuration option for custom facts
  • Loading branch information
bastelfreak committed Feb 13, 2024
2 parents 1c2e140 + ab01ecc commit ec05ede
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def add_custom_fact(name, value, options = {})
# @api private
def self.register_custom_fact(name, value, options)
@custom_facts ||= {}
@custom_facts[name.to_s] = {:options => options, :value => value}
name = RSpec.configuration.facterdb_string_keys ? name.to_s : name.to_sym
@custom_facts[name] = {:options => options, :value => value}
end

# Adds any custom facts according to the rules defined for the operating
Expand Down
17 changes: 11 additions & 6 deletions spec/rspec_puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -899,24 +899,29 @@

it 'adds a simple fact and value' do
add_custom_fact 'root_home', '/root'
expect(subject['redhat-7-x86_64']['root_home']).to eq '/root'
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
end

it 'confines a fact to a particular operating system' do
add_custom_fact 'root_home', '/root', :confine => 'redhat-7-x86_64'
expect(subject['redhat-7-x86_64']['root_home']).to eq '/root'
expect(subject['redhat-6-x86_64']['root_home']).to be_nil
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
expect(subject['redhat-6-x86_64'][:root_home]).to be_nil
end

it 'excludes a fact from a particular operating system' do
add_custom_fact 'root_home', '/root', :exclude => 'redhat-7-x86_64'
expect(subject['redhat-7-x86_64']['root_home']).to be_nil
expect(subject['redhat-6-x86_64']['root_home']).to eq '/root'
expect(subject['redhat-7-x86_64'][:root_home]).to be_nil
expect(subject['redhat-6-x86_64'][:root_home]).to eq '/root'
end

it 'takes a proc as a value' do
add_custom_fact 'root_home', ->(_os, _facts) { '/root' }
expect(subject['redhat-7-x86_64']['root_home']).to eq '/root'
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
end

it 'accepts sym fact key and stores fact key as sym' do
add_custom_fact :root_home, ->(_os, _facts) { '/root' }
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
end
end

Expand Down

0 comments on commit ec05ede

Please sign in to comment.