Skip to content

Commit 4a35815

Browse files
committed
(maint) Fix helpful rubocops and disable hurtful cops
1 parent 04e5cc0 commit 4a35815

File tree

5 files changed

+33
-45
lines changed

5 files changed

+33
-45
lines changed

spec/acceptance/mysql_backup_spec.rb

+14-34
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class { 'mysql::server::backup':
3535
end
3636

3737
describe 'mysqlbackup.sh' do
38-
before(:each) do
38+
# rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
39+
before(:all) do
3940
pre_run
4041
end
4142

@@ -47,16 +48,10 @@ class { 'mysql::server::backup':
4748
end
4849
end
4950

50-
it 'dumps all databases to single file #stdout' do
51+
it 'dumps all databases to single file' do
5152
unless version_is_greater_than('5.7.0')
5253
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
5354
expect(r.stdout).to match(%r{1})
54-
end
55-
end
56-
end
57-
it 'dumps all databases to single file #exit code' do
58-
if version_is_greater_than('5.7.0')
59-
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
6055
expect(r.exit_code).to be_zero
6156
end
6257
end
@@ -70,21 +65,16 @@ class { 'mysql::server::backup':
7065
end
7166
end
7267

73-
it 'creates at least one backup tarball #stdout' do
68+
it 'creates at least one backup tarball' do
7469
unless version_is_greater_than('5.7.0')
7570
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
7671
expect(r.stdout).to match(%r{2})
77-
end
78-
end
79-
end
80-
it 'creates at least one backup tarball #exit code' do
81-
unless version_is_greater_than('5.7.0')
82-
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
8372
expect(r.exit_code).to be_zero
8473
end
8574
end
8675
end
8776
end
77+
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
8878
end
8979

9080
context 'with one file per database' do
@@ -121,7 +111,8 @@ class { 'mysql::server::backup':
121111
end
122112

123113
describe 'mysqlbackup.sh' do
124-
before(:each) do
114+
# rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
115+
before(:all) do
125116
pre_run
126117
end
127118

@@ -133,17 +124,11 @@ class { 'mysql::server::backup':
133124
end
134125
end
135126

136-
%w[backup1 backup2].each do |database|
137-
it 'creates one file per database #stdout' do
138-
unless version_is_greater_than('5.7.0')
127+
it 'creates one file per database' do
128+
unless version_is_greater_than('5.7.0')
129+
%w[backup1 backup2].each do |database|
139130
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
140131
expect(r.stdout).to match(%r{1})
141-
end
142-
end
143-
end
144-
it 'wcreates one file per database #exit code' do # rubocop:disable RSpec/RepeatedExample
145-
unless version_is_greater_than('5.7.0')
146-
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
147132
expect(r.exit_code).to be_zero
148133
end
149134
end
@@ -157,22 +142,17 @@ class { 'mysql::server::backup':
157142
end
158143
end
159144

160-
%w[backup1 backup2].each do |database|
161-
it 'has one file per database per run #stdout' do
162-
unless version_is_greater_than('5.7.0')
145+
it 'has one file per database per run' do
146+
unless version_is_greater_than('5.7.0')
147+
%w[backup1 backup2].each do |database|
163148
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
164149
expect(r.stdout).to match(%r{2})
165-
end
166-
end
167-
end
168-
it 'has one file per database per run #exit code' do # rubocop:disable RSpec/RepeatedExample
169-
unless version_is_greater_than('5.7.0')
170-
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
171150
expect(r.exit_code).to be_zero
172151
end
173152
end
174153
end
175154
end
155+
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
176156
end
177157
end
178158

spec/acceptance/types/mysql_grant_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ class { 'mysql::server':
455455
end
456456

457457
describe 'adding function privileges' do
458+
# rubocop:disable RSpec/ExampleLength
458459
it 'works without errors' do
459460
pp = <<-EOS
460461
exec { 'simplefunc-create':
@@ -477,13 +478,16 @@ class { 'mysql::server':
477478

478479
apply_manifest(pp, catch_failures: true)
479480
end
481+
# rubocop:enable RSpec/ExampleLength
480482

483+
# rubocop:disable RSpec/MultipleExpectations
481484
it 'finds the user' do
482485
shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r|
483486
expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'})
484487
expect(r.stderr).to be_empty
485488
end
486489
end
490+
# rubocop:enable RSpec/MultipleExpectations
487491
end
488492

489493
describe 'proxy privilieges' do

spec/acceptance/types/mysql_user_spec.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,39 @@ class { 'mysql::server': }
4747

4848
pre_run
4949

50+
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
5051
describe 'changing authentication plugin', if: version_is_greater_than('5.5.0') do
51-
it 'should work without errors' do
52+
it 'works without errors' do
5253
pp = <<-EOS
5354
mysql_user { 'ashp@localhost':
5455
plugin => 'auth_socket',
5556
}
5657
EOS
5758

58-
apply_manifest(pp, :catch_failures => true)
59+
apply_manifest(pp, catch_failures: true)
5960
end
6061

61-
it 'should have correct plugin' do
62+
it 'has the correct plugin' do
6263
shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
6364
expect(r.stdout.rstrip).to eq('auth_socket')
6465
expect(r.stderr).to be_empty
6566
end
6667
end
6768

68-
it 'should not have a password' do
69+
it 'does not have a password' do
6970
pre_run
7071
table = if version_is_greater_than('5.7.0')
71-
"authentication_string"
72+
'authentication_string'
7273
else
73-
"password"
74+
'password'
7475
end
7576
shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
7677
expect(r.stdout.rstrip).to be_empty
7778
expect(r.stderr).to be_empty
7879
end
7980
end
8081
end
82+
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
8183
end
8284

8385
context 'using ashp-dash@localhost' do

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
end
279279

280280
describe 'plugin=' do
281+
# rubocop:disable RSpec/NestedGroups
281282
context 'auth_socket' do
282283
context 'MySQL < 5.7.6' do
283284
it 'changes the authentication plugin' do
@@ -304,7 +305,7 @@
304305
context 'MySQL < 5.7.6' do
305306
it 'changes the authentication plugin' do
306307
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string])
307-
provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0')
308+
provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0') # rubocop:disable Metrics/LineLength
308309

309310
provider.expects(:plugin).returns('mysql_native_password')
310311
provider.plugin = 'mysql_native_password'
@@ -314,13 +315,14 @@
314315
context 'MySQL >= 5.7.6' do
315316
it 'changes the authentication plugin' do
316317
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
317-
provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system').returns('0')
318+
provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system').returns('0') # rubocop:disable Metrics/LineLength
318319

319320
provider.expects(:plugin).returns('mysql_native_password')
320321
provider.plugin = 'mysql_native_password'
321322
end
322323
end
323324
end
325+
# rubocop:enable RSpec/NestedGroups
324326
end
325327

326328
describe 'tls_options=' do

tasks/export.rb

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
require 'puppet'
55

66
def get(file, database, user, password)
7-
cmd_string = "mysqldump"
7+
cmd_string = 'mysqldump'
88
cmd_string << " --databases #{database}" unless database.nil?
99
cmd_string << " --user=#{user}" unless user.nil?
1010
cmd_string << " --password=#{password}" unless password.nil?
1111
cmd_string << " > #{file}" unless file.nil?
12-
stdout, stderr, status = Open3.capture3(cmd_string)
13-
raise Puppet::Error, _("stderr: '#{stderr}'") if status != 0
12+
stdout, _stderr, status = Open3.capture3(cmd_string)
13+
raise Puppet::Error, _("stderr: ' %{stderr}') % { stderr: stderr }") if status != 0
1414
{ status: stdout.strip }
1515
end
1616

0 commit comments

Comments
 (0)