Skip to content

Commit 73134ae

Browse files
committed
(maint) fixing rubocop erros
1 parent 469e2bd commit 73134ae

18 files changed

+164
-201
lines changed

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Style/TrailingCommaInArrayLiteral:
6868
Style/SymbolArray:
6969
Description: Using percent style obscures symbolic intent of array's contents.
7070
EnforcedStyle: brackets
71+
inherit_from: ".rubocop_todo.yml"
7172
RSpec/MessageSpies:
7273
EnforcedStyle: receive
7374
Style/Documentation:

.rubocop_todo.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Style/FrozenStringLiteralComment:
2+
Enabled: false
3+
Exclude:
4+
- lib/*

.sync.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
".gitlab-ci.yml":
33
delete: true
4+
".rubocop.yml":
5+
default_configs:
6+
inherit_from: ".rubocop_todo.yml"
7+
require:
8+
- rubocop-rspec
49
".travis.yml":
510
global_env:
611
- HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests"

.travis.yml

-20
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ jobs:
6767
script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"]
6868
services: docker
6969
stage: acceptance
70-
- bundler_args: --with system_tests
71-
before_script:
72-
- "bundle exec rake 'litmus:provision_list[travis_el8]'"
73-
- "bundle exec rake 'litmus:install_agent[puppet5]'"
74-
- "bundle exec rake litmus:install_module"
75-
env: PLATFORMS=travis_el8_puppet5
76-
rvm: 2.5.7
77-
script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"]
78-
services: docker
79-
stage: acceptance
8070
- bundler_args: --with system_tests
8171
before_script:
8272
- "bundle exec rake 'litmus:provision_list[travis_deb]'"
@@ -97,16 +87,6 @@ jobs:
9787
script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"]
9888
services: docker
9989
stage: acceptance
100-
- bundler_args: --with system_tests
101-
before_script:
102-
- "bundle exec rake 'litmus:provision_list[travis_el8]'"
103-
- "bundle exec rake 'litmus:install_agent[puppet6]'"
104-
- "bundle exec rake litmus:install_module"
105-
env: PLATFORMS=travis_el8_puppet6
106-
rvm: 2.5.7
107-
script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"]
108-
services: docker
109-
stage: acceptance
11090
-
11191
env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint"
11292
stage: static

lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def default_impl(acls, id, offset)
3939
if parts.length > 4
4040
resource['auth_option'] = parts.last(parts.length - 4).join(' ')
4141
end
42-
elsif parts[4] =~ %r{^\d}
42+
elsif %r{^\d}.match?(parts[4])
4343
resource['address'] = parts[3] + ' ' + parts[4]
4444
resource['auth_method'] = parts[5]
4545

lib/puppet/functions/postgresql/postgresql_escape.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ def default_impl(input_string)
1717

1818
# Keep generating possible values for tag until we find one that doesn't appear in the input string
1919
tag = Digest::MD5.hexdigest(input_string)[0..5].gsub(%r{\d}, '')
20-
until input_string !~ %r{#{tag}}
21-
tag = Digest::MD5.hexdigest(tag)[0..5].gsub(%r{\d}, '')
22-
end
20+
tag = Digest::MD5.hexdigest(tag)[0..5].gsub(%r{\d}, '') until input_string !~ %r{#{tag}}
2321

2422
"$#{tag}$#{input_string}$#{tag}$"
2523
end
2624

2725
def tag_needed?(input_string)
28-
input_string =~ %r{\$\$} || input_string.end_with?('$')
26+
input_string =~ %r{\$\$} || input_string.end_with?('$') # rubocop:disable Performance/StringInclude
2927
end
3028
end

lib/puppet/provider/postgresql_replication_slot/ruby.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
commands psql: 'psql'
44

55
def self.instances
6-
run_sql_command('SELECT * FROM pg_replication_slots;')[0].split("\n").select { |l| l =~ %r{\|} }.map do |l|
6+
run_sql_command('SELECT * FROM pg_replication_slots;')[0].split("\n").select { |l| l =~ %r{\|} }.map do |l| # rubocop:disable Performance/StringInclude
77
name, *_others = l.strip.split(%r{\s+\|\s+})
88
new(name: name,
99
ensure: :present)

lib/puppet/type/postgresql_psql.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def retrieve
2121

2222
def sync
2323
output, status = provider.run_sql_command(value)
24-
raise("Error executing SQL; psql returned #{status}: '#{output}'") unless status == 0 # rubocop:disable Style/NumericPredicate
24+
raise("Error executing SQL; psql returned #{status}: '#{output}'") unless status == 0
2525
end
2626
end
2727

@@ -36,7 +36,6 @@ def sync
3636
# Return true if a matching row is found
3737
def matches(value)
3838
output, status = provider.run_unless_sql_command(value)
39-
# rubocop:disable Style/NumericPredicate
4039
fail("Error evaluating 'unless' clause, returned #{status}: '#{output}'") unless status == 0 # rubocop:disable Style/SignalException
4140
# rubocop:enable Style/NumericPredicate
4241

@@ -59,8 +58,7 @@ def matches(value)
5958
output, status = provider.run_unless_sql_command(value)
6059
status = output.exitcode if status.nil?
6160

62-
raise("Error evaluating 'onlyif' clause, returned #{status}: '#{output}'") unless status == 0 # rubocop:disable Style/NumericPredicate
63-
61+
raise("Error evaluating 'onlyif' clause, returned #{status}: '#{output}'") unless status == 0
6462
result_count = output.strip.to_i
6563
debug("Found #{result_count} row(s) executing 'onlyif' clause")
6664
result_count > 0
@@ -110,7 +108,7 @@ def matches(value)
110108

111109
validate do |values|
112110
Array(values).each do |value|
113-
unless value =~ %r{\w+=}
111+
unless %r{\w+=}.match?(value)
114112
raise ArgumentError, "Invalid environment setting '#{value}'"
115113
end
116114
end

lib/puppet/util/postgresql_validator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def attempt_connection(sleep_length, tries)
4141
Puppet.debug "PostgresqlValidator.attempt_connection: #{build_validate_cmd}"
4242
result = execute_command
4343
if result && !result.empty?
44-
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name] || parse_connect_settings.select { |elem| elem.match %r{PGDATABASE} }} successful!"
44+
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name] || parse_connect_settings.select { |elem| elem.match %r{PGDATABASE} }} successful!" # rubocop:disable Performance/StringInclude
4545
return true
4646
else
4747
Puppet.warning "PostgresqlValidator.attempt_connection: Sleeping for #{sleep_length} seconds"

spec/acceptance/server/grant_role_spec.rb

+21-27
Original file line numberDiff line numberDiff line change
@@ -157,42 +157,36 @@ class { 'postgresql::server': }
157157
end
158158

159159
it 'grants a role to a user/superuser' do
160-
begin
161-
idempotent_apply(pp_one)
162-
163-
## Check that the role was granted to the user
164-
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
165-
expect(r.stdout).to match(%r{\(1 row\)})
166-
expect(r.stderr).to eq('')
167-
end
168-
## Check that the role was granted to the user
169-
psql('--command="SELECT 1 FROM pg_roles AS r_role JOIN pg_auth_members AS am ON r_role.oid = am.member JOIN pg_roles AS r_group ON r_group.oid = am.roleid WHERE r_group.rolname = \'test_group\' AND r_role.rolname = \'psql_grant_role_tester\'" grant_role_test', 'psql_grant_role_tester') do |r| # rubocop:disable Metrics/LineLength
170-
expect(r.stdout).to match(%r{\(1 row\)})
171-
expect(r.stderr).to eq('')
172-
end
160+
idempotent_apply(pp_one)
161+
162+
## Check that the role was granted to the user
163+
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
164+
expect(r.stdout).to match(%r{\(1 row\)})
165+
expect(r.stderr).to eq('')
166+
end
167+
## Check that the role was granted to the user
168+
psql('--command="SELECT 1 FROM pg_roles AS r_role JOIN pg_auth_members AS am ON r_role.oid = am.member JOIN pg_roles AS r_group ON r_group.oid = am.roleid WHERE r_group.rolname = \'test_group\' AND r_role.rolname = \'psql_grant_role_tester\'" grant_role_test', 'psql_grant_role_tester') do |r| # rubocop:disable Layout/LineLength
169+
expect(r.stdout).to match(%r{\(1 row\)})
170+
expect(r.stderr).to eq('')
173171
end
174172
end
175173

176174
it 'revokes a role from a user' do
177-
begin
178-
apply_manifest(pp_two, catch_failures: true)
179-
apply_manifest(pp_two, expect_changes: true)
180-
181-
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
182-
expect(r.stdout).to match(%r{\(0 rows\)})
183-
expect(r.stderr).to eq('')
184-
end
175+
apply_manifest(pp_two, catch_failures: true)
176+
apply_manifest(pp_two, expect_changes: true)
177+
178+
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
179+
expect(r.stdout).to match(%r{\(0 rows\)})
180+
expect(r.stderr).to eq('')
185181
end
186182
end
187183

188184
it 'does not grant permission to a nonexistent user' do
189-
begin
190-
apply_manifest(pp_three, expect_failures: true)
185+
apply_manifest(pp_three, expect_failures: true)
191186

192-
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
193-
expect(r.stdout).to match(%r{\(0 rows\)})
194-
expect(r.stderr).to eq('')
195-
end
187+
psql('--command="SELECT 1 WHERE pg_has_role(\'psql_grant_role_tester\', \'test_group\', \'MEMBER\') = true" grant_role_test', 'psql_grant_role_tester') do |r|
188+
expect(r.stdout).to match(%r{\(0 rows\)})
189+
expect(r.stderr).to eq('')
196190
end
197191
end
198192
end

0 commit comments

Comments
 (0)