Skip to content

Commit

Permalink
fix tests add rubocop todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
tphoney committed Sep 4, 2017
1 parent 177cacd commit 7fc409e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 16 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Expand Up @@ -2,5 +2,6 @@ fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
"staging": "https://github.com/voxpupuli/puppet-staging"
"translate": "https://github.com/puppetlabs/puppetlabs-translate"
symlinks:
"mysql": "#{source_dir}"
6 changes: 3 additions & 3 deletions .rubocop.yml
@@ -1,6 +1,6 @@
---
require:
# - rubocop-rspec
- rubocop-rspec
- rubocop-i18n
AllCops:
TargetRubyVersion: '2.1'
Expand All @@ -12,9 +12,9 @@ AllCops:
- Gemfile
- Rakefile
- pkg/**/*
# - spec/fixtures/**/*
- spec/**/*
- spec/fixtures/**/*
- vendor/**/*
inherit_from: .rubocop_todo.yml
Metrics/LineLength:
Description: People have wide screens, use them.
Max: 200
Expand Down
123 changes: 123 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,123 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-09-04 11:31:12 +0100 using RuboCop version 0.49.1.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'

# Offense count: 1
Lint/AmbiguousRegexpLiteral:
Exclude:
- 'spec/unit/puppet/type/mysql_grant_spec.rb'

# Offense count: 1
Lint/DuplicatedKey:
Exclude:
- 'spec/classes/mysql_server_backup_spec.rb'

# Offense count: 1
Lint/HandleExceptions:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 1
Lint/ScriptPermission:
Exclude:
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'

# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'

# Offense count: 11
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 351

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- 'spec/acceptance/**/*.rb'
- 'spec/unit/puppet/functions/mysql_password_spec.rb'

# Offense count: 56
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/acceptance/mysql_backup_spec.rb'
- 'spec/acceptance/types/mysql_database_spec.rb'
- 'spec/acceptance/types/mysql_grant_spec.rb'
- 'spec/acceptance/types/mysql_plugin_spec.rb'
- 'spec/acceptance/types/mysql_user_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/classes/mysql_server_monitor_spec.rb'
- 'spec/classes/mysql_server_spec.rb'
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'

# Offense count: 3
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/unit/facter/mysql_server_id_spec.rb'
- 'spec/unit/facter/mysql_version_spec.rb'
- 'spec/unit/facter/mysqld_version_spec.rb'

# Offense count: 41
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/acceptance/mysql_server_spec.rb'
- 'spec/unit/puppet/type/mysql_database_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
- 'spec/unit/puppet/type/mysql_plugin_spec.rb'
- 'spec/unit/puppet/type/mysql_user_spec.rb'

# Offense count: 38
RSpec/MultipleExpectations:
Max: 4

# Offense count: 42
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/acceptance/mysql_backup_spec.rb'
- 'spec/classes/mycnf_template_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/classes/mysql_server_spec.rb'

# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/classes/mysql_server_account_security_spec.rb'

# Offense count: 3
RSpec/ScatteredLet:
Exclude:
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'spec/acceptance/types/mysql_grant_spec.rb'
- 'spec/classes/mycnf_template_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
2 changes: 1 addition & 1 deletion spec/classes/graceful_failures_spec.rb
Expand Up @@ -9,7 +9,7 @@
}
end

it 'gracefullies fail' do
it 'gracefully fails' do
is_expected.to compile.and_raise_error(%r{Unsupported platform:})
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/functions/mysql_password_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'the mysql_password function' do
before :all do
before :all do # rubocop:disable RSpec/BeforeAfterAll
Puppet::Parser::Functions.autoloader.loadall
end

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/provider/mysql_database/mysql_spec.rb
Expand Up @@ -31,7 +31,7 @@
Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql')
File.stubs(:file?).with('/root/.my.cnf').returns(true)
provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('new_database')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF")
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Metrics/LineLength
end

let(:instance) { provider.class.instances.first }
Expand All @@ -40,7 +40,7 @@
it 'returns an array of databases' do
provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases)
raw_databases.each_line do |db|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF")
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Metrics/LineLength
end
databases = provider.class.instances.map { |x| x.name }
expect(parsed_databases).to match_array(databases)
Expand Down
18 changes: 9 additions & 9 deletions spec/unit/puppet/provider/mysql_user/mysql_spec.rb
Expand Up @@ -88,7 +88,7 @@
Puppet::Util.stubs(:which).with('mysqld').returns('/usr/sbin/mysqld')
File.stubs(:file?).with('/root/.my.cnf').returns(true)
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns('joe@localhost')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') # rubocop:disable Metrics/LineLength
end

let(:instance) { provider.class.instances.first }
Expand All @@ -98,7 +98,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand All @@ -108,7 +108,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand All @@ -118,7 +118,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand All @@ -128,7 +128,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand All @@ -138,7 +138,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand All @@ -148,7 +148,7 @@
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['percona-5.5'][:string])
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
parsed_users.each do |user|
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength
end

usernames = provider.class.instances.map { |x| x.name }
Expand Down Expand Up @@ -179,7 +179,7 @@
describe 'create' do
it 'makes a user' do
provider.expects(:mysql).with([defaults_file, system_database, '-e', "CREATE USER 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'"])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) # rubocop:disable Metrics/LineLength
provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"])
provider.expects(:exists?).returns(true)
expect(provider.create).to be_truthy
Expand Down Expand Up @@ -265,7 +265,7 @@
end
it 'changes the hash MySQL >= 5.7.6' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0')
provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') # rubocop:disable Metrics/LineLength

provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5')
provider.password_hash = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'
Expand Down

0 comments on commit 7fc409e

Please sign in to comment.