Merge pull request #390 from apenney/add-more-tests
Add tests for all missing parameters.
This commit is contained in:
commit
9603d9a8aa
8 changed files with 301 additions and 60 deletions
|
@ -6,4 +6,4 @@ license 'Apache 2.0'
|
|||
summary 'Mysql module'
|
||||
description 'Mysql module'
|
||||
project_page 'http://github.com/puppetlabs/puppetlabs-mysql'
|
||||
dependency 'puppetlabs/stdlib', '>= 2.2.1'
|
||||
dependency 'puppetlabs/stdlib', '>= 3.2.0'
|
||||
|
|
|
@ -4,7 +4,7 @@ describe 'mysql::server::backup class' do
|
|||
context 'should work with no errors' do
|
||||
it 'when configuring mysql backups' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
mysql::db { 'backup1':
|
||||
user => 'backup',
|
||||
password => 'secret',
|
||||
|
@ -31,13 +31,14 @@ describe 'mysql::server::backup class' do
|
|||
describe 'mysqlbackup.sh' do
|
||||
it 'should run mysqlbackup.sh with no errors' do
|
||||
shell("/usr/local/sbin/mysqlbackup.sh") do |r|
|
||||
expect(r.stderr).to eq("")
|
||||
expect(r.stderr).to eq("-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.\n")
|
||||
end
|
||||
end
|
||||
|
||||
it 'should dump all databases to single file' do
|
||||
shell('ls /tmp/backups/ | grep -c "mysql_backup_backup1_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do |r|
|
||||
expect(r.stdout).to match(/\d*[13579]/)
|
||||
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
|
||||
expect(r.stdout).to match(/1/)
|
||||
expect(r.exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,7 +49,10 @@ describe 'mysql::server::backup class' do
|
|||
end
|
||||
|
||||
it 'creates at least one backup tarball' do
|
||||
expect(shell('ls /tmp/backups/ | grep -c "mysql_backup_backup1_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"').stdout).to match(/\d*[02468]/)
|
||||
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
|
||||
expect(r.stdout).to match(/2/)
|
||||
expect(r.exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,44 +1,50 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::bindings class' do
|
||||
osfamily = fact('osfamily')
|
||||
operatingsystem = fact('operatingsystem')
|
||||
osfamily = fact('osfamily')
|
||||
operatingsystem = fact('operatingsystem')
|
||||
|
||||
case osfamily
|
||||
when 'RedHat'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
when 'Suse'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'python-mysql'
|
||||
case operatingsystem
|
||||
when /OpenSuSE/
|
||||
ruby_package = 'rubygem-mysql'
|
||||
when /(SLES|SLED)/
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
when 'Debian'
|
||||
java_package = 'libmysql-java'
|
||||
perl_package = 'libdbd-mysql-perl'
|
||||
python_package = 'python-mysqldb'
|
||||
ruby_package = 'libmysql-ruby'
|
||||
when 'FreeBSD'
|
||||
java_package = 'databases/mysql-connector-java'
|
||||
perl_package = 'p5-DBD-mysql'
|
||||
python_package = 'databases/py-MySQLdb'
|
||||
ruby_package = 'ruby-mysql'
|
||||
else
|
||||
case operatingsystem
|
||||
when 'Amazon'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
case osfamily
|
||||
when 'RedHat'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
php_package = 'php-mysql'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
when 'Suse'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
php_package = 'apache2-mod_php5'
|
||||
python_package = 'python-mysql'
|
||||
case operatingsystem
|
||||
when /OpenSuSE/
|
||||
ruby_package = 'rubygem-mysql'
|
||||
when /(SLES|SLED)/
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
when 'Debian'
|
||||
java_package = 'libmysql-java'
|
||||
perl_package = 'libdbd-mysql-perl'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'python-mysqldb'
|
||||
ruby_package = 'libmysql-ruby'
|
||||
when 'FreeBSD'
|
||||
java_package = 'databases/mysql-connector-java'
|
||||
perl_package = 'p5-DBD-mysql'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'databases/py-MySQLdb'
|
||||
ruby_package = 'ruby-mysql'
|
||||
else
|
||||
case operatingsystem
|
||||
when 'Amazon'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mysql::bindings class' do
|
||||
|
||||
describe 'running puppet code' do
|
||||
it 'should work with no errors' do
|
||||
|
@ -52,14 +58,29 @@ describe 'mysql::bindings class' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'enabling bindings' do
|
||||
describe 'all parameters' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::bindings':
|
||||
java_enable => true,
|
||||
perl_enable => true,
|
||||
python_enable => true,
|
||||
ruby_enable => true,
|
||||
java_enable => true,
|
||||
perl_enable => true,
|
||||
python_enable => true,
|
||||
ruby_enable => true,
|
||||
java_package_ensure => present,
|
||||
perl_package_ensure => present,
|
||||
php_package_ensure => present,
|
||||
python_package_ensure => present,
|
||||
ruby_package_ensure => present,
|
||||
java_package_name => #{java_package},
|
||||
perl_package_name => #{perl_package},
|
||||
php_package_name => #{php_package},
|
||||
python_package_name => #{python_package},
|
||||
ruby_package_name => #{ruby_package},
|
||||
java_package_provider => undef,
|
||||
perl_package_provider => undef,
|
||||
php_package_provider => undef,
|
||||
python_package_provider => undef,
|
||||
ruby_package_provider => undef,
|
||||
}
|
||||
EOS
|
||||
|
||||
|
@ -76,6 +97,10 @@ describe 'mysql::bindings class' do
|
|||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(php_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(python_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe 'mysql::db define' do
|
|||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
mysql::db { 'spec1':
|
||||
user => 'root1',
|
||||
password => 'password',
|
||||
|
|
45
spec/acceptance/mysql_server_config_spec.rb
Normal file
45
spec/acceptance/mysql_server_config_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'config location' do
|
||||
it 'creates the file elsewhere' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
config_file => '/etc/testmy.cnf',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/testmy.cnf') do
|
||||
it { should be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'manage_config_file' do
|
||||
it 'wont reset the location of my.cnf' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
config_file => '/etc/my.cnf',
|
||||
manage_config_file => false,
|
||||
}
|
||||
EOS
|
||||
# Make sure this doesn't exist so we can test if puppet
|
||||
# readded it
|
||||
shell('rm /etc/my.cnf')
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/my.cnf') do
|
||||
it { should_not be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'resets' do
|
||||
it 'cleans up' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
shell('rm /etc/testmy.cnf')
|
||||
end
|
||||
end
|
|
@ -3,17 +3,25 @@ require 'spec_helper_acceptance'
|
|||
describe 'mysql class' do
|
||||
case fact('osfamily')
|
||||
when 'RedHat'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysqld'
|
||||
mycnf = '/etc/my.cnf'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysqld'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'Suse'
|
||||
package_name = 'mysql-community-server'
|
||||
service_name = 'mysql'
|
||||
mycnf = '/etc/my.cnf'
|
||||
package_name = 'mysql-community-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'Debian'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
when 'Ubuntu'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'upstart'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
end
|
||||
|
||||
describe 'running puppet code' do
|
||||
|
@ -75,4 +83,157 @@ describe 'mysql class' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'package_ensure => absent' do
|
||||
it 'uninstalls mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
service_enabled => false,
|
||||
package_ensure => absent,
|
||||
package_name => #{package_name}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should_not be_installed }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'package_ensure => present' do
|
||||
it 'installs mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
package_ensure => present,
|
||||
package_name => #{package_name}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'purge_conf_dir' do
|
||||
|
||||
it 'purges the conf dir' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
purge_conf_dir => true
|
||||
}
|
||||
EOS
|
||||
shell('touch /etc/mysql/conf.d/test.conf')
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/mysql/conf.d/test.conf') do
|
||||
it { should_not be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'restart' do
|
||||
it 'stops the service restarting if set' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
restart => false,
|
||||
override_options => { 'mysqld' => { 'test' => 'value' } }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to_not match(/Scheduling refresh/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'root_group' do
|
||||
it 'creates a group' do
|
||||
pp = "group { 'test': ensure => present }"
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'sets the group of files' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
root_group => 'test',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/my.cnf') do
|
||||
it { should be_grouped_into 'test' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'service parameters' do
|
||||
it 'calls all parameters' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
service_enabled => true,
|
||||
service_manage => true,
|
||||
service_name => #{service_name},
|
||||
service_provider => #{service_provider}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'users, grants, and databases' do
|
||||
it 'are created' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
users => {
|
||||
'zerg1@localhost' => {
|
||||
ensure => 'present',
|
||||
max_connections_per_hour => '0',
|
||||
max_queries_per_hour => '0',
|
||||
max_updates_per_hour => '0',
|
||||
max_user_connections => '0',
|
||||
password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF',
|
||||
}
|
||||
},
|
||||
grants => {
|
||||
'zerg1@localhost/zergdb.*' => {
|
||||
ensure => 'present',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
|
||||
table => 'zergdb.*',
|
||||
user => 'zerg1@localhost',
|
||||
}
|
||||
},
|
||||
databases => {
|
||||
'zergdb' => {
|
||||
ensure => 'present',
|
||||
charset => 'utf8',
|
||||
}
|
||||
},
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'has a user' do
|
||||
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'zerg1@localhost'\"") do |r|
|
||||
expect(r.stdout).to match(/^1$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'has a grant' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR zerg1@localhost\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT SELECT, INSERT, UPDATE, DELETE ON `zergdb`.* TO 'zerg1'@'localhost' WITH GRANT OPTION/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'has a database' do
|
||||
shell("mysql -NBe \"SHOW DATABASES LIKE 'zergdb'\"") do |r|
|
||||
expect(r.stdout).to match(/zergdb/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
centos-64-x64.local:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-i386
|
||||
|
|
|
@ -19,8 +19,14 @@ RSpec.configure do |c|
|
|||
# Install module and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'mysql')
|
||||
hosts.each do |host|
|
||||
# Required for binding tests.
|
||||
if fact('osfamily') == 'RedHat'
|
||||
version = fact("operatingsystemmajrelease")
|
||||
shell("rpm -i http://yum.puppetlabs.com/puppetlabs-release-el-#{version}.noarch.rpm")
|
||||
end
|
||||
|
||||
shell('/bin/touch /etc/puppet/hiera.yaml')
|
||||
shell('puppet module install puppetlabs-stdlib --version 2.2.1', { :acceptable_exit_codes => [0,1] })
|
||||
shell('puppet module install puppetlabs-stdlib --version 3.2.0', { :acceptable_exit_codes => [0,1] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue