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

work with symbolized strings #175

Merged
merged 2 commits into from
Jun 9, 2024
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
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-07-06 14:12:32 UTC using RuboCop version 1.50.2.
# on 2024-06-09 13:09:14 UTC using RuboCop version 1.63.5.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -12,7 +12,7 @@ Performance/MapCompact:
Exclude:
- 'lib/rspec-puppet-facts.rb'

# Offense count: 32
# Offense count: 29
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand All @@ -29,7 +29,7 @@ RSpec/ExpectInHook:
Exclude:
- 'spec/rspec_puppet_facts_spec.rb'

# Offense count: 20
# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
Expand All @@ -52,14 +52,14 @@ RSpec/MessageSpies:
RSpec/MultipleExpectations:
Max: 2

# Offense count: 46
# Offense count: 49
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/rspec_puppet_facts_spec.rb'

# Offense count: 14
# Offense count: 13
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 6
Expand Down
12 changes: 6 additions & 6 deletions lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def on_supported_os_implementation(opts = {})
# facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to
# cycle through and downgrade Facter versions per platform type until we find matching Facter data.
filter.each do |filter_spec|
versions = FacterDB.get_facts(filter_spec).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] }
versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] }

version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v }

Expand All @@ -144,7 +144,7 @@ def on_supported_os_implementation(opts = {})

os_facts_hash = {}
received_facts.map do |facts|
os_fact = facts[:os]
os_fact = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
unless os_fact
RspecPuppetFacts.warning "No os fact was found in FacterDB for: #{facts}"
next
Expand All @@ -156,8 +156,6 @@ def on_supported_os_implementation(opts = {})
os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
bastelfreak marked this conversation as resolved.
Show resolved Hide resolved
end

return stringify_keys(os_facts_hash) if RSpec.configuration.facterdb_string_keys

os_facts_hash
end

Expand Down Expand Up @@ -264,6 +262,7 @@ def self.common_facts
if augeas?
@common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version')
end
@common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys

@common_facts
end
Expand Down Expand Up @@ -424,6 +423,7 @@ def self.facter_version_for_puppet_version(puppet_version)

RSpec.configure do |c|
c.add_setting :default_facter_version,
:default => RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
c.add_setting :facterdb_string_keys, :default => false
default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
c.add_setting :facterdb_string_keys,
default: false
end
2 changes: 1 addition & 1 deletion rspec-puppet-facts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'deep_merge', '~> 1.2'
s.add_runtime_dependency 'facter', '< 5'
s.add_runtime_dependency 'facterdb', '>= 0.5.0', '< 2'
s.add_runtime_dependency 'facterdb', '~> 2.1'
s.add_runtime_dependency 'puppet', '>= 7', '< 9'
end
10 changes: 5 additions & 5 deletions spec/fixtures/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"7",
"8"
"11",
"12"
]
},
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"5",
"6",
"7"
"7",
"8",
"9"
]
}
],
Expand Down
Loading