Skip to content

Commit 624de68

Browse files
authored
Merge branch 'main' into CAT-2113-Update_spec_helper
2 parents 654a8bb + d4b6849 commit 624de68

24 files changed

+112
-82
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
cfg:
17-
- {puppet_version: '7', ruby: '2.7'}
18-
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
1917
- {puppet_version: '8', ruby: '3.2'}
2018
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
2119
env:
@@ -52,7 +50,6 @@ jobs:
5250
strategy:
5351
matrix:
5452
cfg:
55-
- {puppet_version: '7', ruby: '2.7'}
5653
- {puppet_version: '8', ruby: '3.2', extra: 'bundle config set with integration'}
5754
env:
5855
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}

.github/workflows/nightly.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
strategy:
1212
matrix:
1313
cfg:
14-
- {puppet_version: '7', ruby: '2.7'}
15-
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
1614
- {puppet_version: '8', ruby: '3.2'}
1715
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
1816
env:
@@ -49,7 +47,6 @@ jobs:
4947
strategy:
5048
matrix:
5149
cfg:
52-
- {puppet_version: '7', ruby: '2.7'}
5350
- {puppet_version: '8', ruby: '3.2', extra: 'bundle config set with integration'}
5451
env:
5552
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}

.rubocop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ inherit_from: .rubocop_todo.yml
33

44
require: rubocop-rspec
55
AllCops:
6-
TargetRubyVersion: '2.5'
6+
NewCops: enable
7+
TargetRubyVersion: '3.1'
78
Include:
89
- "**/*.rb"
910
Exclude:

.rubocop_todo.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-12-19 10:44:38 UTC using RuboCop version 1.48.1.
3+
# on 2025-03-10 20:03:26 UTC using RuboCop version 1.70.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 19
10+
# Configuration parameters: AllowComments, AllowEmptyLambdas.
11+
Lint/EmptyBlock:
12+
Exclude:
13+
- 'lib/puppet/resource_api/value_creator.rb'
14+
- 'spec/puppet/resource_api/base_context_spec.rb'
15+
16+
# Offense count: 12
17+
# Configuration parameters: AllowComments.
18+
Lint/EmptyClass:
19+
Exclude:
20+
- 'lib/puppet/resource_api/type_definition.rb'
21+
- 'lib/puppet/util/network_device/simple/device.rb'
22+
- 'spec/puppet/provider/test_provider/test_provider.rb'
23+
- 'spec/puppet/resource_api/transport/wrapper_spec.rb'
24+
- 'spec/puppet/resource_api/transport_spec.rb'
25+
- 'spec/puppet/resource_api_spec.rb'
26+
927
# Offense count: 25
1028
# Configuration parameters: IgnoredMetadata.
1129
RSpec/DescribeClass:
1230
Enabled: false
1331

14-
# Offense count: 33
32+
# Offense count: 37
1533
# Configuration parameters: CountAsOne.
1634
RSpec/ExampleLength:
1735
Max: 16
@@ -23,7 +41,7 @@ RSpec/InstanceVariable:
2341
- 'spec/acceptance/namevar_spec.rb'
2442
- 'spec/puppet/resource_api/data_type_handling_spec.rb'
2543

26-
# # Offense count: 15
44+
# Offense count: 15
2745
RSpec/LeakyConstantDeclaration:
2846
Exclude:
2947
- 'spec/puppet/resource_api/base_context_spec.rb'
@@ -49,3 +67,47 @@ RSpec/NestedGroups:
4967
RSpec/SubjectStub:
5068
Exclude:
5169
- 'spec/puppet/resource_api/base_context_spec.rb'
70+
71+
# Offense count: 24
72+
# This cop supports unsafe autocorrection (--autocorrect-all).
73+
# Configuration parameters: EnforcedStyle.
74+
# SupportedStyles: constant, string
75+
RSpec/VerifiedDoubleReference:
76+
Exclude:
77+
- 'spec/integration/resource_api_spec.rb'
78+
- 'spec/puppet/resource_api/property_spec.rb'
79+
- 'spec/puppet/resource_api/puppet_context_spec.rb'
80+
- 'spec/puppet/resource_api/simple_provider_spec.rb'
81+
- 'spec/puppet/resource_api/transport_spec.rb'
82+
- 'spec/puppet/resource_api/type_definition_spec.rb'
83+
- 'spec/puppet/resource_api_spec.rb'
84+
85+
# Offense count: 1
86+
# This cop supports unsafe autocorrection (--autocorrect-all).
87+
# Configuration parameters: AllowedReceivers.
88+
Style/CollectionCompact:
89+
Exclude:
90+
- 'lib/puppet/resource_api.rb'
91+
92+
# Offense count: 3
93+
# This cop supports unsafe autocorrection (--autocorrect-all).
94+
# Configuration parameters: AllowSplatArgument.
95+
Style/HashConversion:
96+
Exclude:
97+
- 'lib/puppet/resource_api.rb'
98+
- 'lib/puppet/resource_api/glue.rb'
99+
- 'lib/puppet/resource_api/simple_provider.rb'
100+
101+
# Offense count: 2
102+
# This cop supports unsafe autocorrection (--autocorrect-all).
103+
# Configuration parameters: AllowedReceivers.
104+
# AllowedReceivers: Thread.current
105+
Style/HashEachMethods:
106+
Exclude:
107+
- 'lib/puppet/resource_api/type_definition.rb'
108+
109+
# Offense count: 1
110+
# This cop supports unsafe autocorrection (--autocorrect-all).
111+
Style/SlicingWithRange:
112+
Exclude:
113+
- 'lib/puppet/resource_api.rb'

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ group :tests do
1919
# since the Resource API runs inside the puppetserver, test against the JRuby versions we ship
2020
# these require special dependencies to have everything load properly
2121
# rubocop 1.48 supports JRuby 9.3+, which includes coverage for versions we support
22-
gem 'rubocop', '~> 1.48.1', require: false
22+
gem 'rubocop', '~> 1.70.0', require: false
2323
gem 'rubocop-rspec', '~> 2.20.0', require: false
2424
gem 'rubocop-performance', '~> 1.17.1', require: false
2525
end

contrib/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Code modified from: https://gist.github.com/hanloong/9849098
55
require 'English'
66

7-
changed_files = `git diff --name-only --cached --diff-filter=ACM`.split(/\n/)
7+
changed_files = `git diff --name-only --cached --diff-filter=ACM`.split("\n")
88
changed_files = changed_files.select do |file_name|
99
File.extname(file_name) == '.rb'
1010
end.join(' ')

lib/puppet/resource_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def initialize(attributes)
104104
attributes[:title] = @title if attributes[:title].nil? && !type_definition.namevars.empty?
105105
end
106106

107-
super(attributes)
107+
super
108108
end
109109

110110
def name
@@ -541,8 +541,8 @@ def load_provider(type_name)
541541
end
542542
rescue NameError
543543
if device_name # line too long # rubocop:disable Style/GuardClause
544-
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name}"\
545-
" nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
544+
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name} " \
545+
"nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
546546
else
547547
raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
548548
end

lib/puppet/resource_api/data_type_handling.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def self.boolean_munge(value)
142142
# @private
143143
def self.ambiguous_error_msg(error_msg_prefix, value, type)
144144
"#{error_msg_prefix} #{value.inspect} is not unabiguously convertable to " \
145-
"#{type}"
145+
"#{type}"
146146
end
147147

148148
# Validates the `value` against the specified `type`.
@@ -195,9 +195,9 @@ def self.parse_puppet_type(attr_name, type)
195195
Puppet::Pops::Types::TypeParser.singleton.parse(type)
196196
rescue Puppet::ParseErrorWithIssue => e
197197
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
198-
"`#{type}` could not be parsed: #{e.message}"
198+
"`#{type}` could not be parsed: #{e.message}"
199199
rescue Puppet::ParseError => e
200200
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
201-
"`#{type}` is not recognised: #{e.message}"
201+
"`#{type}` is not recognised: #{e.message}"
202202
end
203203
end

lib/puppet/resource_api/transport.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def self.validate(name, connection_info)
9494
transport_schema = transports[name]
9595
raise Puppet::DevError, format('Transport for `%<target>s` not registered with `%<environment>s`', target: name, environment: current_environment_name) if transport_schema.nil?
9696

97-
clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:"remote-transport")
97+
clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:'remote-transport')
9898

9999
apply_defaults(transport_schema, connection_info)
100100
message_prefix = 'The connection info provided does not match the Transport Schema'

lib/puppet/resource_api/transport/wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def respond_to_missing?(name, _include_private)
4141
(@transport.respond_to? name) || super
4242
end
4343

44-
def method_missing(method_name, *args, &block)
44+
def method_missing(method_name, ...)
4545
if @transport.respond_to? method_name
46-
@transport.send(method_name, *args, &block)
46+
@transport.send(method_name, ...)
4747
else
4848
super
4949
end

lib/puppet/resource_api/type_definition.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def title_patterns
2525
end
2626

2727
def validate_schema(definition, attr_key)
28-
super(definition, attr_key)
28+
super
2929
%i[title provider alias audit before consume export loglevel noop notify require schedule stage subscribe tag].each do |name|
3030
raise Puppet::DevError, format('must not define an attribute called `%<name>s`', name: name.inspect) if definition[attr_key].key? name
3131
end
@@ -234,7 +234,7 @@ def check_schema_values(resource)
234234
next unless attributes[key]
235235

236236
type = @data_type_cache[attributes[key][:type]]
237-
is_sensitive = (attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true))
237+
is_sensitive = attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true)
238238
error_message = Puppet::ResourceApi::DataTypeHandling.try_validate(
239239
type,
240240
value,

spec/acceptance/device_spec.rb

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@
88
RSpec.describe 'exercising a device provider' do
99
let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' }
1010
let(:default_type_values) do
11-
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF '\
12-
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 '\
13-
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
14-
end
15-
16-
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
17-
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.4.0')
18-
# work around https://tickets.puppetlabs.com/browse/PUP-8632 and https://tickets.puppetlabs.com/browse/PUP-9047
19-
FileUtils.mkdir_p(File.expand_path('~/.puppetlabs/opt/puppet/cache/devices/the_node/state'))
20-
end
11+
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF ' \
12+
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 ' \
13+
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
2114
end
2215

2316
describe 'using `puppet resource`' do
@@ -32,8 +25,8 @@
3225

3326
it 'deals with canonicalized resources correctly' do
3427
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
35-
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
36-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
28+
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
29+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
3730
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
3831
expect(stdout_str).to match(/#{stdmatch}/)
3932
expect(status).not_to be_success
@@ -45,8 +38,8 @@
4538

4639
it 'deals with canonicalized resources correctly' do
4740
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
48-
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
49-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
41+
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
42+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
5043
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
5144
expect(stdout_str).to match(/#{stdmatch}/)
5245
expect(status).to be_success
@@ -103,12 +96,7 @@
10396
DEVICE_CREDS
10497
end
10598

106-
def is_device_apply_supported?
107-
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
108-
end
109-
11099
before do
111-
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
112100
device_conf.write(device_conf_content)
113101
device_conf.close
114102

@@ -155,9 +143,9 @@ def is_device_apply_supported?
155143
it 'applies the catalog successfully' do
156144
Tempfile.create('fact_set') do |f|
157145
f.write 'device_provider{ "foo":' \
158-
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", '\
159-
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, '\
160-
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
146+
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", ' \
147+
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, ' \
148+
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
161149
f.close
162150

163151
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")

spec/acceptance/multi_device_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
DEVICE_CONF
2828
end
2929

30-
def is_device_apply_supported?
31-
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
32-
end
33-
3430
before do
35-
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
3631
device_conf.write(device_conf_content)
3732
device_conf.close
3833
end

spec/acceptance/sensitive_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@
1717
end
1818

1919
it 'is not exposed by a provider' do
20-
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
21-
"optional_secret => Sensitive('optional sesitive_data'), array_secret => [Sensitive('array sesitive_data')] }\"")
20+
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
21+
"optional_secret => Sensitive('optional sesitive_data'), array_secret => [Sensitive('array sesitive_data')] }\"")
2222
expect(stdout_str).to match(/redacted/)
2323
expect(stdout_str).not_to match(/sesitive_data/)
2424
expect(stdout_str).not_to match(/warn|error/i)
2525
end
2626

2727
context 'when a sensitive value is not the top level type' do
2828
it 'is not exposed by a provider' do
29-
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
30-
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive('variant sesitive_data')] }\"")
29+
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
30+
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive('variant sesitive_data')] }\"")
3131
expect(stdout_str).to match(/redacted/)
3232
expect(stdout_str).not_to match(/variant sesitive_data/)
3333
expect(stdout_str).not_to match(/warn|error/i)
3434
end
3535

3636
it 'properly validates the sensitive type value' do
37-
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
38-
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive(134679)] }\"")
37+
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
38+
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive(134679)] }\"")
3939
expect(stdout_str).to match(/Sensitive\[String\]( value)?, got Sensitive\[Integer\]/)
4040
expect(stdout_str).not_to match(/134679/)
4141
end

spec/acceptance/transport/transport_defaults_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323
end
2424
let(:device_credentials) { Tempfile.new('credentials.txt') }
2525

26-
def is_device_apply_supported?
27-
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
28-
end
29-
3026
before do
31-
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
3227
device_conf.write(device_conf_content)
3328
device_conf.close
3429

spec/acceptance/transport/transport_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323
end
2424
let(:device_credentials) { Tempfile.new('credentials.txt') }
2525

26-
def is_device_apply_supported?
27-
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
28-
end
29-
3026
before do
31-
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
3227
device_conf.write(device_conf_content)
3328
device_conf.close
3429

spec/puppet/resource_api/data_type_handling_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
context "when validating #{valid_value.inspect}" do
9292
let(:value) { valid_value }
9393

94-
it { expect(error_msg).to be nil }
94+
it { expect(error_msg).to be_nil }
9595
end
9696
end
9797
testcase[:invalid].each do |invalid_value|

0 commit comments

Comments
 (0)