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

Use facterdb_string_keys configuration option for custom facts #157

Merged
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
2 changes: 1 addition & 1 deletion ext/puppet_agent_components.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,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 @@ -901,24 +901,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