rspec-puppet-facts 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.rubocop_todo.yml +62 -5
- data/CHANGELOG.md +21 -0
- data/Gemfile +4 -4
- data/README.md +1 -1
- data/Rakefile +7 -7
- data/lib/rspec-puppet-facts/version.rb +1 -1
- data/lib/rspec-puppet-facts.rb +41 -58
- data/rspec-puppet-facts.gemspec +2 -2
- data/spec/fixtures/metadata.json +5 -5
- data/spec/rspec_puppet_facts_spec.rb +211 -322
- metadata +9 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26b5f9acb794f67889cc8d24cb1bc35b73e0c20d1e855f88ac8d65cf1ca8cbbf
|
4
|
+
data.tar.gz: 920bd51e0f0def41e2f7ea8a38aa26b7247d8e311b3cda87b08eaa592fdecda1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7290dffe6d55a28fa8fc721c03c394b2715a6fa282a8af544ab5ab7fa6428976592b8cd0e853f88bce10f70bfcd403fb49b77b0ba74ddb37823bdd5b19bdcc03
|
7
|
+
data.tar.gz: 5d23c2f0ae77ecc1a562e0e3aa079ff0c097f48c495d4c39cc17e486f4bbb3d6974a6a3f458d5b05df294c461e209df718ea342b270b9cae6a4d298a9db9e6f4
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2024-06-09 17:48:43 UTC using RuboCop version 1.63.5.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -12,7 +12,7 @@ Performance/MapCompact:
|
|
12
12
|
Exclude:
|
13
13
|
- 'lib/rspec-puppet-facts.rb'
|
14
14
|
|
15
|
-
# Offense count:
|
15
|
+
# Offense count: 29
|
16
16
|
# Configuration parameters: Prefixes, AllowedPatterns.
|
17
17
|
# Prefixes: when, with, without
|
18
18
|
RSpec/ContextWording:
|
@@ -29,7 +29,7 @@ RSpec/ExpectInHook:
|
|
29
29
|
Exclude:
|
30
30
|
- 'spec/rspec_puppet_facts_spec.rb'
|
31
31
|
|
32
|
-
# Offense count:
|
32
|
+
# Offense count: 8
|
33
33
|
# This cop supports safe autocorrection (--autocorrect).
|
34
34
|
# Configuration parameters: EnforcedStyle.
|
35
35
|
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
|
@@ -52,14 +52,14 @@ RSpec/MessageSpies:
|
|
52
52
|
RSpec/MultipleExpectations:
|
53
53
|
Max: 2
|
54
54
|
|
55
|
-
# Offense count:
|
55
|
+
# Offense count: 40
|
56
56
|
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
57
57
|
# SupportedStyles: always, named_only
|
58
58
|
RSpec/NamedSubject:
|
59
59
|
Exclude:
|
60
60
|
- 'spec/rspec_puppet_facts_spec.rb'
|
61
61
|
|
62
|
-
# Offense count:
|
62
|
+
# Offense count: 13
|
63
63
|
# Configuration parameters: AllowedGroups.
|
64
64
|
RSpec/NestedGroups:
|
65
65
|
Max: 6
|
@@ -74,3 +74,60 @@ RSpec/StubbedMock:
|
|
74
74
|
Rake/Desc:
|
75
75
|
Exclude:
|
76
76
|
- 'Rakefile'
|
77
|
+
|
78
|
+
# Offense count: 6
|
79
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
80
|
+
# Configuration parameters: EnforcedStyle.
|
81
|
+
# SupportedStyles: always, always_true, never
|
82
|
+
Style/FrozenStringLiteralComment:
|
83
|
+
Exclude:
|
84
|
+
- 'Gemfile'
|
85
|
+
- 'Rakefile'
|
86
|
+
- 'lib/rspec-puppet-facts.rb'
|
87
|
+
- 'lib/rspec-puppet-facts/version.rb'
|
88
|
+
- 'spec/rspec_puppet_facts_spec.rb'
|
89
|
+
- 'spec/spec_helper.rb'
|
90
|
+
|
91
|
+
# Offense count: 1
|
92
|
+
Style/MixinUsage:
|
93
|
+
Exclude:
|
94
|
+
- 'spec/spec_helper.rb'
|
95
|
+
|
96
|
+
# Offense count: 3
|
97
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
98
|
+
# Configuration parameters: EnforcedStyle.
|
99
|
+
# SupportedStyles: literals, strict
|
100
|
+
Style/MutableConstant:
|
101
|
+
Exclude:
|
102
|
+
- 'lib/rspec-puppet-facts.rb'
|
103
|
+
- 'lib/rspec-puppet-facts/version.rb'
|
104
|
+
- 'spec/rspec_puppet_facts_spec.rb'
|
105
|
+
|
106
|
+
# Offense count: 1
|
107
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
108
|
+
# Configuration parameters: Methods.
|
109
|
+
Style/RedundantArgument:
|
110
|
+
Exclude:
|
111
|
+
- 'lib/rspec-puppet-facts.rb'
|
112
|
+
|
113
|
+
# Offense count: 1
|
114
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
115
|
+
Style/RedundantSort:
|
116
|
+
Exclude:
|
117
|
+
- 'lib/rspec-puppet-facts.rb'
|
118
|
+
|
119
|
+
# Offense count: 2
|
120
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
121
|
+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
|
122
|
+
# AllowedMethods: present?, blank?, presence, try, try!
|
123
|
+
Style/SafeNavigation:
|
124
|
+
Exclude:
|
125
|
+
- 'lib/rspec-puppet-facts.rb'
|
126
|
+
|
127
|
+
# Offense count: 2
|
128
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
129
|
+
# Configuration parameters: RequireEnglish, EnforcedStyle.
|
130
|
+
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
|
131
|
+
Style/SpecialGlobalVars:
|
132
|
+
Exclude:
|
133
|
+
- 'lib/rspec-puppet-facts.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [4.0.0](https://github.com/voxpupuli/rspec-puppet-facts/tree/4.0.0) (2024-06-10)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/voxpupuli/rspec-puppet-facts/compare/3.0.0...4.0.0)
|
6
|
+
|
7
|
+
**Breaking changes:**
|
8
|
+
|
9
|
+
- Rely on modern facts [\#178](https://github.com/voxpupuli/rspec-puppet-facts/pull/178) ([ekohl](https://github.com/ekohl))
|
10
|
+
- Require FacterDB 2.x [\#176](https://github.com/voxpupuli/rspec-puppet-facts/pull/176) ([bastelfreak](https://github.com/bastelfreak))
|
11
|
+
|
12
|
+
**Implemented enhancements:**
|
13
|
+
|
14
|
+
- work with symbolized strings [\#175](https://github.com/voxpupuli/rspec-puppet-facts/pull/175) ([bastelfreak](https://github.com/bastelfreak))
|
15
|
+
|
16
|
+
**Merged pull requests:**
|
17
|
+
|
18
|
+
- rubocop: Fix Layout cops [\#182](https://github.com/voxpupuli/rspec-puppet-facts/pull/182) ([bastelfreak](https://github.com/bastelfreak))
|
19
|
+
- Use max\_by to determine the maximum value [\#181](https://github.com/voxpupuli/rspec-puppet-facts/pull/181) ([ekohl](https://github.com/ekohl))
|
20
|
+
- rubocop: Fix Style cops [\#180](https://github.com/voxpupuli/rspec-puppet-facts/pull/180) ([bastelfreak](https://github.com/bastelfreak))
|
21
|
+
- Use more native rspec matchers in tests [\#179](https://github.com/voxpupuli/rspec-puppet-facts/pull/179) ([ekohl](https://github.com/ekohl))
|
22
|
+
- Update voxpupuli-rubocop requirement from ~\> 2.6.0 to ~\> 2.7.0 [\#171](https://github.com/voxpupuli/rspec-puppet-facts/pull/171) ([dependabot[bot]](https://github.com/apps/dependabot))
|
23
|
+
|
3
24
|
## [3.0.0](https://github.com/voxpupuli/rspec-puppet-facts/tree/3.0.0) (2024-03-23)
|
4
25
|
|
5
26
|
[Full Changelog](https://github.com/voxpupuli/rspec-puppet-facts/compare/2.0.5...3.0.0)
|
data/Gemfile
CHANGED
@@ -2,14 +2,14 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'facter', ENV
|
5
|
+
gem 'facter', ENV.fetch('FACTER_GEM_VERSION', nil), require: false
|
6
6
|
|
7
7
|
group :release do
|
8
8
|
gem 'faraday-retry', '~> 2.1', require: false
|
9
9
|
gem 'github_changelog_generator', '~> 1.16.4', require: false
|
10
10
|
end
|
11
11
|
|
12
|
-
group :coverage, optional: ENV['COVERAGE']!='yes' do
|
13
|
-
gem 'codecov', :
|
14
|
-
gem 'simplecov-console', :
|
12
|
+
group :coverage, optional: ENV['COVERAGE'] != 'yes' do
|
13
|
+
gem 'codecov', require: false
|
14
|
+
gem 'simplecov-console', require: false
|
15
15
|
end
|
data/README.md
CHANGED
@@ -98,7 +98,7 @@ end
|
|
98
98
|
|
99
99
|
## Specifying a default Facter version
|
100
100
|
|
101
|
-
By default, `
|
101
|
+
By default, `on_supported_os` will return the facts for the version of Facter
|
102
102
|
that it has loaded (usually this is Facter 2.5.1). This behaviour can be
|
103
103
|
overridden by setting the `default_facter_version` RSpec setting in your
|
104
104
|
`spec/spec_helper.rb` file.
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PUPPET_VERSIONS_PATH = File.join(__dir__, 'ext', 'puppet_agent_components.json')
|
2
2
|
|
3
3
|
begin
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'yard'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
YARD::Rake::YardocTask.new
|
8
8
|
rescue LoadError
|
9
9
|
# yard is optional
|
10
10
|
end
|
@@ -40,8 +40,8 @@ namespace :puppet_versions do
|
|
40
40
|
|
41
41
|
output = `git status --porcelain #{PUPPET_VERSIONS_PATH}`
|
42
42
|
unless output.strip.empty?
|
43
|
-
|
44
|
-
|
43
|
+
warn "#{PUPPET_VERSIONS_PATH} is out of date."
|
44
|
+
warn 'Run the puppet_versions:update task to update it and commit the changes.'
|
45
45
|
raise
|
46
46
|
end
|
47
47
|
end
|
@@ -54,7 +54,7 @@ rescue LoadError
|
|
54
54
|
else
|
55
55
|
require 'rubygems'
|
56
56
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
57
|
-
config.exclude_labels = %w
|
57
|
+
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog github_actions]
|
58
58
|
config.user = 'voxpupuli'
|
59
59
|
config.project = 'rspec-puppet-facts'
|
60
60
|
gem_version = Gem::Specification.load("#{config.project}.gemspec").version
|
data/lib/rspec-puppet-facts.rb
CHANGED
@@ -58,8 +58,7 @@ module RspecPuppetFacts
|
|
58
58
|
# @api private
|
59
59
|
def on_supported_os_implementation(opts = {})
|
60
60
|
unless /\A\d+\.\d+(?:\.\d+)*\z/.match?((facterversion = opts[:facterversion]))
|
61
|
-
raise ArgumentError, ":facterversion must be in the format 'n.n' or "
|
62
|
-
"'n.n.n' (n is numeric), not '#{facterversion}'"
|
61
|
+
raise ArgumentError, ":facterversion must be in the format 'n.n' or 'n.n.n' (n is numeric), not '#{facterversion}'"
|
63
62
|
end
|
64
63
|
|
65
64
|
filter = []
|
@@ -67,7 +66,6 @@ module RspecPuppetFacts
|
|
67
66
|
if os_sup['operatingsystemrelease']
|
68
67
|
Array(os_sup['operatingsystemrelease']).map do |operatingsystemmajrelease|
|
69
68
|
opts[:hardwaremodels].each do |hardwaremodel|
|
70
|
-
|
71
69
|
os_release_filter = "/^#{Regexp.escape(operatingsystemmajrelease.split(' ')[0])}/"
|
72
70
|
case os_sup['operatingsystem']
|
73
71
|
when /BSD/i
|
@@ -82,48 +80,46 @@ module RspecPuppetFacts
|
|
82
80
|
"/^#{operatingsystemmajrelease}-/"
|
83
81
|
end
|
84
82
|
when /Windows/i
|
85
|
-
hardwaremodel =
|
83
|
+
hardwaremodel = 'x86_64'
|
86
84
|
os_sup['operatingsystem'] = os_sup['operatingsystem'].downcase
|
87
85
|
operatingsystemmajrelease = operatingsystemmajrelease[/\A(?:Server )?(.+)/i, 1]
|
88
86
|
|
89
87
|
# force quoting because windows releases can contain spaces
|
90
88
|
os_release_filter = "\"#{operatingsystemmajrelease}\""
|
91
|
-
|
92
|
-
if operatingsystemmajrelease == '2016' && Puppet::Util::Package.versioncmp(facterversion, '3.4') < 0
|
93
|
-
os_release_filter = '/^10\\.0\\./'
|
94
|
-
end
|
95
89
|
when /Amazon/i
|
96
90
|
# Tighten the regex for Amazon Linux 2 so that we don't pick up Amazon Linux 2016 or 2017 facts
|
97
|
-
os_release_filter =
|
91
|
+
os_release_filter = '/^2$/' if operatingsystemmajrelease == '2'
|
98
92
|
end
|
99
93
|
|
100
94
|
filter << {
|
101
|
-
|
102
|
-
|
103
|
-
|
95
|
+
'os.name' => os_sup['operatingsystem'],
|
96
|
+
'os.release.full' => os_release_filter,
|
97
|
+
'os.hardware' => hardwaremodel,
|
104
98
|
}
|
105
99
|
end
|
106
100
|
end
|
107
101
|
else
|
108
102
|
opts[:hardwaremodels].each do |hardwaremodel|
|
109
103
|
filter << {
|
110
|
-
|
111
|
-
|
104
|
+
'os.name' => os_sup['operatingsystem'],
|
105
|
+
'os.hardware' => hardwaremodel,
|
112
106
|
}
|
113
107
|
end
|
114
108
|
end
|
115
109
|
end
|
116
110
|
|
117
|
-
strict_requirement = RspecPuppetFacts
|
111
|
+
strict_requirement = RspecPuppetFacts.facter_version_to_strict_requirement(facterversion)
|
118
112
|
|
119
|
-
loose_requirement = RspecPuppetFacts
|
113
|
+
loose_requirement = RspecPuppetFacts.facter_version_to_loose_requirement(facterversion)
|
120
114
|
received_facts = []
|
121
115
|
|
122
116
|
# FacterDB may have newer versions of facter data for which it contains a subset of all possible
|
123
117
|
# facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to
|
124
118
|
# cycle through and downgrade Facter versions per platform type until we find matching Facter data.
|
125
119
|
filter.each do |filter_spec|
|
126
|
-
versions = FacterDB.get_facts(filter_spec).to_h
|
120
|
+
versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h do |facts|
|
121
|
+
[Gem::Version.new(facts[:facterversion]), facts]
|
122
|
+
end
|
127
123
|
|
128
124
|
version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v }
|
129
125
|
|
@@ -131,9 +127,7 @@ module RspecPuppetFacts
|
|
131
127
|
version, facts = versions.select { |v, _f| loose_requirement =~ v }.max_by { |v, _f| v } if loose_requirement
|
132
128
|
next unless version
|
133
129
|
|
134
|
-
if RspecPuppetFacts.spec_facts_strict?
|
135
|
-
raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting"
|
136
|
-
end
|
130
|
+
raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting" if RspecPuppetFacts.spec_facts_strict?
|
137
131
|
|
138
132
|
RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead"
|
139
133
|
end
|
@@ -148,33 +142,19 @@ module RspecPuppetFacts
|
|
148
142
|
|
149
143
|
os_facts_hash = {}
|
150
144
|
received_facts.map do |facts|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
elsif facts[:operatingsystem] == 'OpenBSD'
|
156
|
-
operatingsystemmajrelease = facts[:operatingsystemrelease]
|
157
|
-
elsif facts[:operatingsystem] == 'windows' && facts[:operatingsystemrelease].start_with?('10.0.')
|
158
|
-
operatingsystemmajrelease = '2016'
|
159
|
-
elsif facts.dig(:os, 'release', 'major')
|
160
|
-
operatingsystemmajrelease = facts[:os]['release']['major']
|
161
|
-
elsif facts.dig(:os, 'distro', 'release', 'major')
|
162
|
-
operatingsystemmajrelease = facts[:os]['distro']['release']['major']
|
163
|
-
else
|
164
|
-
if facts[:operatingsystemmajrelease].nil?
|
165
|
-
operatingsystemmajrelease = facts[:operatingsystemrelease].split('.')[0]
|
166
|
-
else
|
167
|
-
operatingsystemmajrelease = facts[:operatingsystemmajrelease]
|
168
|
-
end
|
145
|
+
os_fact = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
|
146
|
+
unless os_fact
|
147
|
+
RspecPuppetFacts.warning "No os fact was found in FacterDB for: #{facts}"
|
148
|
+
next
|
169
149
|
end
|
170
|
-
|
171
|
-
|
150
|
+
|
151
|
+
os = "#{os_fact['name'].downcase}-#{os_fact['release']['major']}-#{os_fact['hardware']}"
|
152
|
+
next if RspecPuppetFacts.spec_facts_os_filter && !os.start_with?(RspecPuppetFacts.spec_facts_os_filter)
|
153
|
+
|
172
154
|
facts.merge! RspecPuppetFacts.common_facts
|
173
155
|
os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
|
174
156
|
end
|
175
157
|
|
176
|
-
return stringify_keys(os_facts_hash) if RSpec.configuration.facterdb_string_keys
|
177
|
-
|
178
158
|
os_facts_hash
|
179
159
|
end
|
180
160
|
|
@@ -212,7 +192,7 @@ module RspecPuppetFacts
|
|
212
192
|
def self.register_custom_fact(name, value, options)
|
213
193
|
@custom_facts ||= {}
|
214
194
|
name = RSpec.configuration.facterdb_string_keys ? name.to_s : name.to_sym
|
215
|
-
@custom_facts[name] = {:
|
195
|
+
@custom_facts[name] = { options: options, value: value }
|
216
196
|
end
|
217
197
|
|
218
198
|
# Adds any custom facts according to the rules defined for the operating
|
@@ -231,7 +211,7 @@ module RspecPuppetFacts
|
|
231
211
|
value = fact[:value].respond_to?(:call) ? fact[:value].call(os, facts) : fact[:value]
|
232
212
|
# if merge_facts passed, merge supplied facts into facts hash
|
233
213
|
if fact[:options][:merge_facts]
|
234
|
-
facts.deep_merge!({name => value})
|
214
|
+
facts.deep_merge!({ name => value })
|
235
215
|
else
|
236
216
|
facts[name] = value
|
237
217
|
end
|
@@ -254,7 +234,7 @@ module RspecPuppetFacts
|
|
254
234
|
# @return [nil,String]
|
255
235
|
# @api private
|
256
236
|
def self.spec_facts_os_filter
|
257
|
-
ENV
|
237
|
+
ENV.fetch('SPEC_FACTS_OS', nil)
|
258
238
|
end
|
259
239
|
|
260
240
|
# If SPEC_FACTS_STRICT is set to `yes`, RspecPuppetFacts will error on missing FacterDB entries, instead of warning & skipping the tests, or using an older facter version.
|
@@ -270,10 +250,11 @@ module RspecPuppetFacts
|
|
270
250
|
# @return [Hash <Symbol => String>]
|
271
251
|
def self.common_facts
|
272
252
|
return @common_facts if @common_facts
|
253
|
+
|
273
254
|
@common_facts = {
|
274
|
-
:
|
275
|
-
:
|
276
|
-
:
|
255
|
+
puppetversion: Puppet.version,
|
256
|
+
rubysitedir: RbConfig::CONFIG['sitelibdir'],
|
257
|
+
rubyversion: RUBY_VERSION,
|
277
258
|
}
|
278
259
|
|
279
260
|
@common_facts[:mco_version] = MCollective::VERSION if mcollective?
|
@@ -281,6 +262,7 @@ module RspecPuppetFacts
|
|
281
262
|
if augeas?
|
282
263
|
@common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version')
|
283
264
|
end
|
265
|
+
@common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys
|
284
266
|
|
285
267
|
@common_facts
|
286
268
|
end
|
@@ -317,8 +299,9 @@ module RspecPuppetFacts
|
|
317
299
|
# @api private
|
318
300
|
def self.meta_supported_os
|
319
301
|
unless metadata['operatingsystem_support'].is_a? Array
|
320
|
-
|
302
|
+
raise StandardError, 'Unknown operatingsystem support in the metadata file!'
|
321
303
|
end
|
304
|
+
|
322
305
|
metadata['operatingsystem_support']
|
323
306
|
end
|
324
307
|
|
@@ -330,8 +313,9 @@ module RspecPuppetFacts
|
|
330
313
|
def self.metadata
|
331
314
|
return @metadata if @metadata
|
332
315
|
unless File.file? metadata_file
|
333
|
-
|
316
|
+
raise StandardError, "Can't find metadata.json... dunno why"
|
334
317
|
end
|
318
|
+
|
335
319
|
content = File.read metadata_file
|
336
320
|
@metadata = JSON.parse content
|
337
321
|
end
|
@@ -347,7 +331,7 @@ module RspecPuppetFacts
|
|
347
331
|
# @param message [String]
|
348
332
|
# @api private
|
349
333
|
def self.warning(message)
|
350
|
-
|
334
|
+
warn message
|
351
335
|
end
|
352
336
|
|
353
337
|
# Reset the memoization
|
@@ -397,7 +381,7 @@ module RspecPuppetFacts
|
|
397
381
|
elsif /\A[0-9]+\Z/.match?(version)
|
398
382
|
# Interpret 3 as < 4
|
399
383
|
"< #{version.to_i + 1}"
|
400
|
-
else
|
384
|
+
else # rubocop:disable Style/EmptyElse
|
401
385
|
# This would be the same as the strict requirement
|
402
386
|
nil
|
403
387
|
end
|
@@ -415,13 +399,13 @@ module RspecPuppetFacts
|
|
415
399
|
fd = File.open(json_path, 'rb:UTF-8')
|
416
400
|
data = JSON.parse(fd.read)
|
417
401
|
|
418
|
-
version_map = data.map
|
402
|
+
version_map = data.map do |_, versions|
|
419
403
|
if versions['puppet'].nil? || versions['facter'].nil?
|
420
404
|
nil
|
421
405
|
else
|
422
406
|
[Gem::Version.new(versions['puppet']), versions['facter']]
|
423
407
|
end
|
424
|
-
|
408
|
+
end.compact
|
425
409
|
|
426
410
|
puppet_gem_version = Gem::Version.new(puppet_version)
|
427
411
|
applicable_versions = version_map.select { |p, _| puppet_gem_version >= p }
|
@@ -430,7 +414,7 @@ module RspecPuppetFacts
|
|
430
414
|
return Facter.version
|
431
415
|
end
|
432
416
|
|
433
|
-
applicable_versions.
|
417
|
+
applicable_versions.max_by { |p, _| p }.last
|
434
418
|
rescue JSON::ParserError
|
435
419
|
warning "#{json_path} contains invalid JSON, defaulting to Facter #{Facter.version}"
|
436
420
|
Facter.version
|
@@ -440,7 +424,6 @@ module RspecPuppetFacts
|
|
440
424
|
end
|
441
425
|
|
442
426
|
RSpec.configure do |c|
|
443
|
-
c.add_setting :default_facter_version,
|
444
|
-
|
445
|
-
c.add_setting :facterdb_string_keys, :default => false
|
427
|
+
c.add_setting :default_facter_version, default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
|
428
|
+
c.add_setting :facterdb_string_keys, default: false
|
446
429
|
end
|
data/rspec-puppet-facts.gemspec
CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'rspec', '~> 3.12'
|
24
24
|
s.add_development_dependency 'yard', '~> 0.9.34'
|
25
25
|
|
26
|
-
s.add_development_dependency 'voxpupuli-rubocop', '~> 2.
|
26
|
+
s.add_development_dependency 'voxpupuli-rubocop', '~> 2.7.0'
|
27
27
|
|
28
28
|
s.add_runtime_dependency 'deep_merge', '~> 1.2'
|
29
29
|
s.add_runtime_dependency 'facter', '< 5'
|
30
|
-
s.add_runtime_dependency 'facterdb', '
|
30
|
+
s.add_runtime_dependency 'facterdb', '~> 2.1'
|
31
31
|
s.add_runtime_dependency 'puppet', '>= 7', '< 9'
|
32
32
|
end
|
data/spec/fixtures/metadata.json
CHANGED
@@ -15,16 +15,16 @@
|
|
15
15
|
{
|
16
16
|
"operatingsystem": "Debian",
|
17
17
|
"operatingsystemrelease": [
|
18
|
-
"
|
19
|
-
"
|
18
|
+
"11",
|
19
|
+
"12"
|
20
20
|
]
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"operatingsystem": "RedHat",
|
24
24
|
"operatingsystemrelease": [
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
25
|
+
"7",
|
26
|
+
"8",
|
27
|
+
"9"
|
28
28
|
]
|
29
29
|
}
|
30
30
|
],
|