Rewrite some of the unit tests to work on more platforms.

This commit introduces puppet_facts, a gem that allows easier testing
against PE platforms.  We're using this gem to automatically parse the
metadata.json and test against appropriate versions of PE on platforms
we support.

We start by only running against centos-6-x86_64 and ubuntu 14.04 on a
regular basis but this is implemented as an ENV so it can be overwritten
by CI systems to test against all PE platforms.
This commit is contained in:
Hunter Haugen 2014-07-27 22:51:22 -07:00 committed by Ashley Penney
parent 994ac1a058
commit 1812fbca25
11 changed files with 441 additions and 422 deletions

View file

@ -1,6 +1,5 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
"puppet_facts": "https://github.com/apenney/puppet_facts"
symlinks:
"mysql": "#{source_dir}"

View file

@ -6,14 +6,14 @@ group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'puppet_facts', :require => false
end
if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
gem 'beaker-rspec', '>= 2.2', :require => false
end
if puppetversion = ENV['PUPPET_GEM_VERSION']

View file

@ -20,7 +20,8 @@ class mysql::server::config {
}
if $mysql::server::manage_config_file {
file { $mysql::server::config_file:
file { 'mysql-config-file':
path => $mysql::server::config_file,
content => template('mysql/my.cnf.erb'),
mode => '0644',
}

View file

@ -0,0 +1,16 @@
require 'spec_helper'
describe 'mysql::server' do
on_pe_unsupported_platforms.each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
context 'should gracefully fail' do
it { should_not contain_class('mysql::server') }
it { should raise_error(/Unsupported osfamily: foo/) }
end
end
end
end
end

View file

@ -1,27 +1,23 @@
require 'spec_helper'
describe 'mysql::client' do
fail ArgumentError, "Puppet facts missing" if Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].empty?
Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].each do |facts|
platform_name = facts.gsub(/\.facts/, '')
describe "on #{platform_name}" do
hash = {}
File.read(facts).each_line do |line|
key, value = line.split(' => ')
hash[key.to_sym] = value.chomp unless value.nil?
end
let(:facts) { hash }
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
context 'with defaults' do
it { should_not contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
end
context 'with defaults' do
it { should_not contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
end
context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }}
context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }}
it { should contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
it { should contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
end
end
end
end
end

View file

@ -1,41 +1,40 @@
require 'spec_helper'
describe 'mysql::server::account_security' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts.merge({:fqdn => 'myhost.mydomain', :hostname => 'myhost'}) }
let :facts do {
:fqdn => 'myhost.mydomain',
:hostname => 'myhost',
:root_home => '/root'
}
end
it 'should remove Mysql_User[root@myhost.mydomain]' do
should contain_mysql_user('root@myhost.mydomain').with_ensure('absent')
end
it 'should remove Mysql_User[root@myhost]' do
should contain_mysql_user('root@myhost').with_ensure('absent')
end
it 'should remove Mysql_User[root@127.0.0.1]' do
should contain_mysql_user('root@127.0.0.1').with_ensure('absent')
end
it 'should remove Mysql_User[root@::1]' do
should contain_mysql_user('root@::1').with_ensure('absent')
end
it 'should remove Mysql_User[@myhost.mydomain]' do
should contain_mysql_user('@myhost.mydomain').with_ensure('absent')
end
it 'should remove Mysql_User[@myhost]' do
should contain_mysql_user('@myhost').with_ensure('absent')
end
it 'should remove Mysql_User[@localhost]' do
should contain_mysql_user('@localhost').with_ensure('absent')
end
it 'should remove Mysql_User[@%]' do
should contain_mysql_user('@%').with_ensure('absent')
end
it 'should remove Mysql_User[root@myhost.mydomain]' do
should contain_mysql_user('root@myhost.mydomain').with_ensure('absent')
it 'should remove Mysql_database[test]' do
should contain_mysql_database('test').with_ensure('absent')
end
end
end
end
it 'should remove Mysql_User[root@myhost]' do
should contain_mysql_user('root@myhost').with_ensure('absent')
end
it 'should remove Mysql_User[root@127.0.0.1]' do
should contain_mysql_user('root@127.0.0.1').with_ensure('absent')
end
it 'should remove Mysql_User[root@::1]' do
should contain_mysql_user('root@::1').with_ensure('absent')
end
it 'should remove Mysql_User[@myhost.mydomain]' do
should contain_mysql_user('@myhost.mydomain').with_ensure('absent')
end
it 'should remove Mysql_User[@myhost]' do
should contain_mysql_user('@myhost').with_ensure('absent')
end
it 'should remove Mysql_User[@localhost]' do
should contain_mysql_user('@localhost').with_ensure('absent')
end
it 'should remove Mysql_User[@%]' do
should contain_mysql_user('@%').with_ensure('absent')
end
it 'should remove Mysql_database[test]' do
should contain_mysql_database('test').with_ensure('absent')
end
end

View file

@ -1,188 +1,196 @@
require 'spec_helper'
describe 'mysql::server::backup' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
let(:default_params) {
{ 'backupuser' => 'testuser',
let(:default_params) {
{ 'backupuser' => 'testuser',
'backuppassword' => 'testpass',
'backupdir' => '/tmp',
'backuprotate' => '25',
'delete_before_dump' => true,
'execpath' => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
}
}
}
context 'standard conditions' do
let(:params) { default_params }
it { should contain_mysql_user('testuser@localhost').with(
context 'standard conditions' do
let(:params) { default_params }
it { should contain_mysql_user('testuser@localhost').with(
:require => 'Class[Mysql::Server::Root_password]'
)}
)}
it { should contain_mysql_grant('testuser@localhost/*.*').with(
it { should contain_mysql_grant('testuser@localhost/*.*').with(
:privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW", "PROCESS"]
)}
)}
it { should contain_cron('mysql-backup').with(
it { should contain_cron('mysql-backup').with(
:command => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
)}
)}
it { should contain_file('mysqlbackup.sh').with(
it { should contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
) }
it { should contain_file('mysqlbackupdir').with(
it { should contain_file('mysqlbackupdir').with(
:path => '/tmp',
:ensure => 'directory'
)}
)}
it 'should have compression by default' do
it 'should have compression by default' do
verify_contents(subject, 'mysqlbackup.sh', [
' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2',
' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2',
])
end
it 'should skip backing up events table by default' do
end
it 'should skip backing up events table by default' do
verify_contents(subject, 'mysqlbackup.sh', [
'EVENTS="--ignore-table=mysql.event"',
'EVENTS="--ignore-table=mysql.event"',
])
end
end
it 'should have 25 days of rotation' do
it 'should have 25 days of rotation' do
# MySQL counts from 0 I guess.
should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/)
end
end
it 'should have a standard PATH' do
it 'should have a standard PATH' do
should contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin})
end
end
end
context 'custom ownership and mode for backupdir' do
let(:params) do
context 'custom ownership and mode for backupdir' do
let(:params) do
{ :backupdirmode => '0750',
:backupdirowner => 'testuser',
:backupdirgroup => 'testgrp',
:backupdirowner => 'testuser',
:backupdirgroup => 'testgrp',
}.merge(default_params)
end
end
it { should contain_file('mysqlbackupdir').with(
it { should contain_file('mysqlbackupdir').with(
:path => '/tmp',
:ensure => 'directory',
:mode => '0750',
:owner => 'testuser',
:group => 'testgrp'
) }
end
) }
end
context 'with compression disabled' do
let(:params) do
context 'with compression disabled' do
let(:params) do
{ :backupcompress => false }.merge(default_params)
end
end
it { should contain_file('mysqlbackup.sh').with(
it { should contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
) }
it 'should be able to disable compression' do
it 'should be able to disable compression' do
verify_contents(subject, 'mysqlbackup.sh', [
' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql',
' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql',
])
end
end
end
context 'with mysql.events backedup' do
let(:params) do
context 'with mysql.events backedup' do
let(:params) do
{ :ignore_events => false }.merge(default_params)
end
end
it { should contain_file('mysqlbackup.sh').with(
it { should contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
) }
it 'should be able to backup events table' do
it 'should be able to backup events table' do
verify_contents(subject, 'mysqlbackup.sh', [
'EVENTS="--events"',
'EVENTS="--events"',
])
end
end
end
context 'with database list specified' do
let(:params) do
context 'with database list specified' do
let(:params) do
{ :backupdatabases => ['mysql'] }.merge(default_params)
end
end
it { should contain_file('mysqlbackup.sh').with(
it { should contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
) }
it 'should have a backup file for each database' do
it 'should have a backup file for each database' do
content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content]
content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date')
# verify_contents(subject, 'mysqlbackup.sh', [
# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql',
# ])
end
end
end
end
context 'with file per database' do
let(:params) do
context 'with file per database' do
let(:params) do
default_params.merge({ :file_per_database => true })
end
end
it 'should loop through backup all databases' do
it 'should loop through backup all databases' do
verify_contents(subject, 'mysqlbackup.sh', [
'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname',
'do',
' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\',
' ${EVENTS} \\',
' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2',
'done',
'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname',
'do',
' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\',
' ${EVENTS} \\',
' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2',
'done',
])
end
end
context 'with compression disabled' do
context 'with compression disabled' do
let(:params) do
default_params.merge({ :file_per_database => true, :backupcompress => false })
default_params.merge({ :file_per_database => true, :backupcompress => false })
end
it 'should loop through backup all databases without compression' do
verify_contents(subject, 'mysqlbackup.sh', [
' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql',
])
verify_contents(subject, 'mysqlbackup.sh', [
' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql',
])
end
end
end
context 'with postscript' do
let(:params) do
default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' })
end
it 'should be add postscript' do
verify_contents(subject, 'mysqlbackup.sh', [
'rsync -a /tmp backup01.local-lan:',
])
end
end
context 'with postscripts' do
let(:params) do
default_params.merge({ :postscript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]})
end
it 'should be add postscript' do
verify_contents(subject, 'mysqlbackup.sh', [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
])
end
end
end
end
context 'with postscript' do
let(:params) do
default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' })
end
it 'should be add postscript' do
verify_contents(subject, 'mysqlbackup.sh', [
'rsync -a /tmp backup01.local-lan:',
])
end
end
context 'with postscripts' do
let(:params) do
default_params.merge({ :postscript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]})
end
it 'should be add postscript' do
verify_contents(subject, 'mysqlbackup.sh', [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
])
end
end
end
end

View file

@ -1,31 +1,35 @@
require 'spec_helper'
describe 'mysql::server::monitor' do
let :facts do
{ :osfamily => 'Debian', :root_home => '/root' }
end
let :pre_condition do
"include 'mysql::server'"
end
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
let :pre_condition do
"include 'mysql::server'"
end
let :default_params do
{
:mysql_monitor_username => 'monitoruser',
:mysql_monitor_password => 'monitorpass',
:mysql_monitor_hostname => 'monitorhost',
}
let :default_params do
{
:mysql_monitor_username => 'monitoruser',
:mysql_monitor_password => 'monitorpass',
:mysql_monitor_hostname => 'monitorhost',
}
end
let :params do
default_params
end
it { should contain_mysql_user('monitoruser@monitorhost')}
it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with(
:ensure => 'present',
:user => 'monitoruser@monitorhost',
:table => '*.*',
:privileges => ["PROCESS", "SUPER"],
:require => 'Mysql_user[monitoruser@monitorhost]'
)}
end
end
end
let :params do
default_params
end
it { should contain_mysql_user('monitoruser@monitorhost')}
it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with(
:ensure => 'present',
:user => 'monitoruser@monitorhost',
:table => '*.*',
:privileges => ["PROCESS", "SUPER"],
:require => 'Mysql_user[monitoruser@monitorhost]'
)}
end

View file

@ -1,5 +1,13 @@
require 'spec_helper'
describe 'mysql::server::mysqltuner' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
it { should contain_file('/usr/local/bin/mysqltuner') }
it { should contain_file('/usr/local/bin/mysqltuner') }
end
end
end
end

View file

@ -1,256 +1,239 @@
require 'spec_helper'
describe 'mysql::server' do
let(:facts) {{:osfamily => 'RedHat', :root_home => '/root'}}
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
context 'with defaults' do
it { should contain_class('mysql::server::install') }
it { should contain_class('mysql::server::config') }
it { should contain_class('mysql::server::service') }
it { should contain_class('mysql::server::root_password') }
it { should contain_class('mysql::server::providers') }
end
context 'with defaults' do
it { should contain_class('mysql::server::install') }
it { should contain_class('mysql::server::config') }
it { should contain_class('mysql::server::service') }
it { should contain_class('mysql::server::root_password') }
it { should contain_class('mysql::server::providers') }
end
# make sure that overriding the mysqld settings keeps the defaults for everything else
context 'with overrides' do
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
}).with_content(/basedir/)
end
end
# make sure that overriding the mysqld settings keeps the defaults for everything else
context 'with overrides' do
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
it do
should contain_file('mysql-config-file').with({
:mode => '0644',
}).with_content(/basedir/)
end
end
describe 'with multiple instance of an option' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}}
it do
should contain_file('/etc/my.cnf').with_content(
/^replicate-do-db = base1$/
).with_content(
/^replicate-do-db = base2$/
).with_content(
/^replicate-do-db = base3$/
)
end
end
describe 'with multiple instance of an option' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}}
it do
should contain_file('mysql-config-file').with_content(
/^replicate-do-db = base1$/
).with_content(
/^replicate-do-db = base2$/
).with_content(
/^replicate-do-db = base3$/
)
end
end
describe 'an option set to true' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true } }}
}
it do
should contain_file('/etc/my.cnf').with_content(/^\s*ssl\s*(?:$|= true)/m)
end
end
describe 'an option set to true' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true } }}
}
it do
should contain_file('mysql-config-file').with_content(/^\s*ssl\s*(?:$|= true)/m)
end
end
describe 'an option set to false' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => false } }}
}
it do
should contain_file('/etc/my.cnf').with_content(/^\s*ssl = false/m)
end
end
describe 'an option set to false' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => false } }}
}
it do
should contain_file('mysql-config-file').with_content(/^\s*ssl = false/m)
end
end
context 'with remove_default_accounts set' do
let (:params) {{ :remove_default_accounts => true }}
it { should contain_class('mysql::server::account_security') }
end
context 'with remove_default_accounts set' do
let (:params) {{ :remove_default_accounts => true }}
it { should contain_class('mysql::server::account_security') }
end
describe 'possibility of disabling ssl completely' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }}
}
it do
should contain_file('/etc/my.cnf').without_content(/^\s*ssl\s*(?:$|= true)/m)
end
end
describe 'possibility of disabling ssl completely' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }}
}
it do
should contain_file('mysql-config-file').without_content(/^\s*ssl\s*(?:$|= true)/m)
end
end
context 'mysql::server::install' do
let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }}
it do
should contain_package('mysql-server').with({
:ensure => :present,
:name => 'mysql-server',
})
end
end
context 'mysql::server::install' do
let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }}
it do
should contain_package('mysql-server').with({
:ensure => :present,
:name => 'mysql-server',
})
end
end
context 'mysql::server::install on RHEL 7' do
let :facts do
{ :osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => 7
}
end
if pe_platform =~ /redhat-7/
context 'mysql::server::install on RHEL 7' do
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }}
it do
should contain_package('mysql-server').with({
:ensure => :present,
:name => 'mariadb-server',
})
end
end
end
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }}
it do
should contain_package('mysql-server').with({
:ensure => :present,
:name => 'mariadb-server',
})
end
end
context 'mysql::server::config' do
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it do
should contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end
context 'mysql::server::install on CentOS 7' do
let :facts do
{ :osfamily => 'RedHat',
:operatingsystem => 'CentOS',
:operatingsystemmajrelease => 7
}
end
it do
should contain_file('mysql-config-file').with({
:mode => '0644',
})
end
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }}
it do
should contain_package('mysql-server').with({
:ensure => :present,
:name => 'mariadb-server',
})
end
end
it do
should contain_file('mysql-config-file').with_content(/!includedir/)
end
end
context 'mysql::server::config' do
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it do
should contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end
context 'without includedir' do
let(:params) {{ :includedir => '' }}
it do
should_not contain_file('mysql-config-file').with({
:ensure => :directory,
:mode => '0755',
})
end
it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
})
end
it do
should contain_file('mysql-config-file').with({
:mode => '0644',
})
end
it do
should contain_file('/etc/my.cnf').with_content(/!includedir/)
end
end
it do
should contain_file('mysql-config-file').without_content(/!includedir/)
end
end
end
context 'without includedir' do
let(:params) {{ :includedir => '' }}
it do
should_not contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end
context 'mysql::server::service' do
context 'with defaults' do
it { should contain_service('mysqld') }
end
it do
should contain_file('/etc/my.cnf').with({
:mode => '0644',
})
end
context 'service_enabled set to false' do
let(:params) {{ :service_enabled => false }}
it do
should contain_file('/etc/my.cnf').without_content(/!includedir/)
it do
should contain_service('mysqld').with({
:ensure => :stopped
})
end
end
end
context 'mysql::server::root_password' do
describe 'when defaults' do
it { should_not contain_mysql_user('root@localhost') }
it { should_not contain_file('/root/.my.cnf') }
end
describe 'when set' do
let(:params) {{:root_password => 'SET' }}
it { should contain_mysql_user('root@localhost') }
it { should contain_file('/root/.my.cnf') }
end
end
context 'mysql::server::providers' do
describe 'with users' do
let(:params) {{:users => {
'foo@localhost' => {
'max_connections_per_hour' => '1',
'max_queries_per_hour' => '2',
'max_updates_per_hour' => '3',
'max_user_connections' => '4',
'password_hash' => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
},
'foo2@localhost' => {}
}}}
it { should contain_mysql_user('foo@localhost').with(
:max_connections_per_hour => '1',
:max_queries_per_hour => '2',
:max_updates_per_hour => '3',
:max_user_connections => '4',
:password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
)}
it { should contain_mysql_user('foo2@localhost').with(
:max_connections_per_hour => nil,
:max_queries_per_hour => nil,
:max_updates_per_hour => nil,
:max_user_connections => nil,
:password_hash => ''
)}
end
describe 'with grants' do
let(:params) {{:grants => {
'foo@localhost/somedb.*' => {
'user' => 'foo@localhost',
'table' => 'somedb.*',
'privileges' => ["SELECT", "UPDATE"],
'options' => ["GRANT"],
},
'foo2@localhost/*.*' => {
'user' => 'foo2@localhost',
'table' => '*.*',
'privileges' => ["SELECT"],
},
}}}
it { should contain_mysql_grant('foo@localhost/somedb.*').with(
:user => 'foo@localhost',
:table => 'somedb.*',
:privileges => ["SELECT", "UPDATE"],
:options => ["GRANT"]
)}
it { should contain_mysql_grant('foo2@localhost/*.*').with(
:user => 'foo2@localhost',
:table => '*.*',
:privileges => ["SELECT"],
:options => nil
)}
end
describe 'with databases' do
let(:params) {{:databases => {
'somedb' => {
'charset' => 'latin1',
'collate' => 'latin1',
},
'somedb2' => {}
}}}
it { should contain_mysql_database('somedb').with(
:charset => 'latin1',
:collate => 'latin1'
)}
it { should contain_mysql_database('somedb2')}
end
end
end
end
end
context 'mysql::server::service' do
context 'with defaults' do
it { should contain_service('mysqld') }
end
context 'service_enabled set to false' do
let(:params) {{ :service_enabled => false }}
it do
should contain_service('mysqld').with({
:ensure => :stopped
})
end
end
end
context 'mysql::server::root_password' do
describe 'when defaults' do
it { should_not contain_mysql_user('root@localhost') }
it { should_not contain_file('/root/.my.cnf') }
end
describe 'when set' do
let(:params) {{:root_password => 'SET' }}
it { should contain_mysql_user('root@localhost') }
it { should contain_file('/root/.my.cnf') }
end
end
context 'mysql::server::providers' do
describe 'with users' do
let(:params) {{:users => {
'foo@localhost' => {
'max_connections_per_hour' => '1',
'max_queries_per_hour' => '2',
'max_updates_per_hour' => '3',
'max_user_connections' => '4',
'password_hash' => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
},
'foo2@localhost' => {}
}}}
it { should contain_mysql_user('foo@localhost').with(
:max_connections_per_hour => '1',
:max_queries_per_hour => '2',
:max_updates_per_hour => '3',
:max_user_connections => '4',
:password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
)}
it { should contain_mysql_user('foo2@localhost').with(
:max_connections_per_hour => nil,
:max_queries_per_hour => nil,
:max_updates_per_hour => nil,
:max_user_connections => nil,
:password_hash => ''
)}
end
describe 'with grants' do
let(:params) {{:grants => {
'foo@localhost/somedb.*' => {
'user' => 'foo@localhost',
'table' => 'somedb.*',
'privileges' => ["SELECT", "UPDATE"],
'options' => ["GRANT"],
},
'foo2@localhost/*.*' => {
'user' => 'foo2@localhost',
'table' => '*.*',
'privileges' => ["SELECT"],
},
}}}
it { should contain_mysql_grant('foo@localhost/somedb.*').with(
:user => 'foo@localhost',
:table => 'somedb.*',
:privileges => ["SELECT", "UPDATE"],
:options => ["GRANT"]
)}
it { should contain_mysql_grant('foo2@localhost/*.*').with(
:user => 'foo2@localhost',
:table => '*.*',
:privileges => ["SELECT"],
:options => nil
)}
end
describe 'with databases' do
let(:params) {{:databases => {
'somedb' => {
'charset' => 'latin1',
'collate' => 'latin1',
},
'somedb2' => {}
}}}
it { should contain_mysql_database('somedb').with(
:charset => 'latin1',
:collate => 'latin1'
)}
it { should contain_mysql_database('somedb2')}
end
end
end

View file

@ -1,5 +1,10 @@
require 'simplecov'
SimpleCov.start do
add_filter "/spec/"
end
require 'puppetlabs_spec_helper/module_spec_helper'
require 'puppet_facts'
include PuppetFacts
RSpec.configure do |c|
c.formatter = :documentation
end
# The default set of platforms to test again.
ENV['UNIT_TEST_PLATFORMS'] = 'centos-6-x86_64 ubuntu-1404-x86_64'
PLATFORMS = ENV['UNIT_TEST_PLATFORMS'].split(' ')