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: fixtures:
repositories: repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib" "stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
"puppet_facts": "https://github.com/apenney/puppet_facts"
symlinks: symlinks:
"mysql": "#{source_dir}" "mysql": "#{source_dir}"

View file

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

View file

@ -20,7 +20,8 @@ class mysql::server::config {
} }
if $mysql::server::manage_config_file { 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'), content => template('mysql/my.cnf.erb'),
mode => '0644', 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 describe 'mysql::client' do
fail ArgumentError, "Puppet facts missing" if Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].empty? on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].each do |facts| pe_platforms.each do |pe_platform,facts|
platform_name = facts.gsub(/\.facts/, '') describe "on #{pe_version} #{pe_platform}" do
describe "on #{platform_name}" do let(:facts) { facts }
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 }
context 'with defaults' do context 'with defaults' do
it { should_not contain_class('mysql::bindings') } it { should_not contain_class('mysql::bindings') }
it { should contain_package('mysql_client') } it { should contain_package('mysql_client') }
end end
context 'with bindings enabled' do context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }} let(:params) {{ :bindings_enable => true }}
it { should contain_class('mysql::bindings') } it { should contain_class('mysql::bindings') }
it { should contain_package('mysql_client') } it { should contain_package('mysql_client') }
end
end end
end end
end end
end end

View file

@ -1,41 +1,40 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server::account_security' do 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 { it 'should remove Mysql_User[root@myhost.mydomain]' do
:fqdn => 'myhost.mydomain', should contain_mysql_user('root@myhost.mydomain').with_ensure('absent')
:hostname => 'myhost', end
:root_home => '/root' it 'should remove Mysql_User[root@myhost]' do
} should contain_mysql_user('root@myhost').with_ensure('absent')
end 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 it 'should remove Mysql_database[test]' do
should contain_mysql_user('root@myhost.mydomain').with_ensure('absent') should contain_mysql_database('test').with_ensure('absent')
end
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 end

View file

@ -1,188 +1,196 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server::backup' do 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) { let(:default_params) {
{ 'backupuser' => 'testuser', { 'backupuser' => 'testuser',
'backuppassword' => 'testpass', 'backuppassword' => 'testpass',
'backupdir' => '/tmp', 'backupdir' => '/tmp',
'backuprotate' => '25', 'backuprotate' => '25',
'delete_before_dump' => true, 'delete_before_dump' => true,
'execpath' => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', '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]' :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"] :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', :command => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present' :ensure => 'present'
)} )}
it { should contain_file('mysqlbackup.sh').with( it { should contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh', :path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present' :ensure => 'present'
) } ) }
it { should contain_file('mysqlbackupdir').with( it { should contain_file('mysqlbackupdir').with(
:path => '/tmp', :path => '/tmp',
:ensure => 'directory' :ensure => 'directory'
)} )}
it 'should have compression by default' do it 'should have compression by default' do
verify_contents(subject, 'mysqlbackup.sh', [ 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 end
it 'should skip backing up events table by default' do it 'should skip backing up events table by default' do
verify_contents(subject, 'mysqlbackup.sh', [ 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. # MySQL counts from 0 I guess.
should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) 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}) should contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin})
end
end end
end
context 'custom ownership and mode for backupdir' do context 'custom ownership and mode for backupdir' do
let(:params) do let(:params) do
{ :backupdirmode => '0750', { :backupdirmode => '0750',
:backupdirowner => 'testuser', :backupdirowner => 'testuser',
:backupdirgroup => 'testgrp', :backupdirgroup => 'testgrp',
}.merge(default_params) }.merge(default_params)
end end
it { should contain_file('mysqlbackupdir').with( it { should contain_file('mysqlbackupdir').with(
:path => '/tmp', :path => '/tmp',
:ensure => 'directory', :ensure => 'directory',
:mode => '0750', :mode => '0750',
:owner => 'testuser', :owner => 'testuser',
:group => 'testgrp' :group => 'testgrp'
) } ) }
end end
context 'with compression disabled' do context 'with compression disabled' do
let(:params) do let(:params) do
{ :backupcompress => false }.merge(default_params) { :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', :path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present' :ensure => 'present'
) } ) }
it 'should be able to disable compression' do it 'should be able to disable compression' do
verify_contents(subject, 'mysqlbackup.sh', [ 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
end
context 'with mysql.events backedup' do context 'with mysql.events backedup' do
let(:params) do let(:params) do
{ :ignore_events => false }.merge(default_params) { :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', :path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present' :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', [ verify_contents(subject, 'mysqlbackup.sh', [
'EVENTS="--events"', 'EVENTS="--events"',
]) ])
end
end end
end
context 'with database list specified' do context 'with database list specified' do
let(:params) do let(:params) do
{ :backupdatabases => ['mysql'] }.merge(default_params) { :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', :path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present' :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 = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content]
content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date')
# verify_contents(subject, 'mysqlbackup.sh', [ # verify_contents(subject, 'mysqlbackup.sh', [
# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', # ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql',
# ]) # ])
end
end end
end
context 'with file per database' do context 'with file per database' do
let(:params) do let(:params) do
default_params.merge({ :file_per_database => true }) 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', [ verify_contents(subject, 'mysqlbackup.sh', [
'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname', 'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname',
'do', 'do',
' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\', ' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\',
' ${EVENTS} \\', ' ${EVENTS} \\',
' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2', ' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2',
'done', 'done',
]) ])
end end
context 'with compression disabled' do context 'with compression disabled' do
let(:params) do let(:params) do
default_params.merge({ :file_per_database => true, :backupcompress => false }) default_params.merge({ :file_per_database => true, :backupcompress => false })
end end
it 'should loop through backup all databases without compression' do it 'should loop through backup all databases without compression' do
verify_contents(subject, 'mysqlbackup.sh', [ verify_contents(subject, 'mysqlbackup.sh', [
' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql', ' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql',
]) ])
end 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 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' require 'spec_helper'
describe 'mysql::server::monitor' do describe 'mysql::server::monitor' do
let :facts do on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
{ :osfamily => 'Debian', :root_home => '/root' } pe_platforms.each do |pe_platform,facts|
end describe "on #{pe_version} #{pe_platform}" do
let :pre_condition do let(:facts) { facts }
"include 'mysql::server'" let :pre_condition do
end "include 'mysql::server'"
end
let :default_params do let :default_params do
{ {
:mysql_monitor_username => 'monitoruser', :mysql_monitor_username => 'monitoruser',
:mysql_monitor_password => 'monitorpass', :mysql_monitor_password => 'monitorpass',
:mysql_monitor_hostname => 'monitorhost', :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 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

View file

@ -1,5 +1,13 @@
require 'spec_helper'
describe 'mysql::server::mysqltuner' do 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 end

View file

@ -1,256 +1,239 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server' do 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 context 'with defaults' do
it { should contain_class('mysql::server::install') } it { should contain_class('mysql::server::install') }
it { should contain_class('mysql::server::config') } it { should contain_class('mysql::server::config') }
it { should contain_class('mysql::server::service') } it { should contain_class('mysql::server::service') }
it { should contain_class('mysql::server::root_password') } it { should contain_class('mysql::server::root_password') }
it { should contain_class('mysql::server::providers') } it { should contain_class('mysql::server::providers') }
end end
# make sure that overriding the mysqld settings keeps the defaults for everything else # make sure that overriding the mysqld settings keeps the defaults for everything else
context 'with overrides' do context 'with overrides' do
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }} let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
it do it do
should contain_file('/etc/my.cnf').with({ should contain_file('mysql-config-file').with({
:mode => '0644', :mode => '0644',
}).with_content(/basedir/) }).with_content(/basedir/)
end end
end end
describe 'with multiple instance of an option' do describe 'with multiple instance of an option' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}} let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}}
it do it do
should contain_file('/etc/my.cnf').with_content( should contain_file('mysql-config-file').with_content(
/^replicate-do-db = base1$/ /^replicate-do-db = base1$/
).with_content( ).with_content(
/^replicate-do-db = base2$/ /^replicate-do-db = base2$/
).with_content( ).with_content(
/^replicate-do-db = base3$/ /^replicate-do-db = base3$/
) )
end end
end end
describe 'an option set to true' do describe 'an option set to true' do
let(:params) { let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true } }} { :override_options => { 'mysqld' => { 'ssl' => true } }}
} }
it do it do
should contain_file('/etc/my.cnf').with_content(/^\s*ssl\s*(?:$|= true)/m) should contain_file('mysql-config-file').with_content(/^\s*ssl\s*(?:$|= true)/m)
end end
end end
describe 'an option set to false' do describe 'an option set to false' do
let(:params) { let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => false } }} { :override_options => { 'mysqld' => { 'ssl' => false } }}
} }
it do it do
should contain_file('/etc/my.cnf').with_content(/^\s*ssl = false/m) should contain_file('mysql-config-file').with_content(/^\s*ssl = false/m)
end end
end end
context 'with remove_default_accounts set' do context 'with remove_default_accounts set' do
let (:params) {{ :remove_default_accounts => true }} let (:params) {{ :remove_default_accounts => true }}
it { should contain_class('mysql::server::account_security') } it { should contain_class('mysql::server::account_security') }
end end
describe 'possibility of disabling ssl completely' do describe 'possibility of disabling ssl completely' do
let(:params) { let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }} { :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }}
} }
it do it do
should contain_file('/etc/my.cnf').without_content(/^\s*ssl\s*(?:$|= true)/m) should contain_file('mysql-config-file').without_content(/^\s*ssl\s*(?:$|= true)/m)
end end
end end
context 'mysql::server::install' do context 'mysql::server::install' do
let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }} let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }}
it do it do
should contain_package('mysql-server').with({ should contain_package('mysql-server').with({
:ensure => :present, :ensure => :present,
:name => 'mysql-server', :name => 'mysql-server',
}) })
end end
end end
context 'mysql::server::install on RHEL 7' do if pe_platform =~ /redhat-7/
let :facts do context 'mysql::server::install on RHEL 7' do
{ :osfamily => 'RedHat', let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }}
:operatingsystem => 'RedHat', it do
:operatingsystemmajrelease => 7 should contain_package('mysql-server').with({
} :ensure => :present,
end :name => 'mariadb-server',
})
end
end
end
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }} context 'mysql::server::config' do
it do context 'with includedir' do
should contain_package('mysql-server').with({ let(:params) {{ :includedir => '/etc/my.cnf.d' }}
:ensure => :present, it do
:name => 'mariadb-server', should contain_file('/etc/my.cnf.d').with({
}) :ensure => :directory,
end :mode => '0755',
end })
end
context 'mysql::server::install on CentOS 7' do it do
let :facts do should contain_file('mysql-config-file').with({
{ :osfamily => 'RedHat', :mode => '0644',
:operatingsystem => 'CentOS', })
:operatingsystemmajrelease => 7 end
}
end
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }} it do
it do should contain_file('mysql-config-file').with_content(/!includedir/)
should contain_package('mysql-server').with({ end
:ensure => :present, end
:name => 'mariadb-server',
})
end
end
context 'mysql::server::config' do context 'without includedir' do
context 'with includedir' do let(:params) {{ :includedir => '' }}
let(:params) {{ :includedir => '/etc/my.cnf.d' }} it do
it do should_not contain_file('mysql-config-file').with({
should contain_file('/etc/my.cnf.d').with({ :ensure => :directory,
:ensure => :directory, :mode => '0755',
:mode => '0755', })
}) end
end
it do it do
should contain_file('/etc/my.cnf').with({ should contain_file('mysql-config-file').with({
:mode => '0644', :mode => '0644',
}) })
end end
it do it do
should contain_file('/etc/my.cnf').with_content(/!includedir/) should contain_file('mysql-config-file').without_content(/!includedir/)
end end
end end
end
context 'without includedir' do context 'mysql::server::service' do
let(:params) {{ :includedir => '' }} context 'with defaults' do
it do it { should contain_service('mysqld') }
should_not contain_file('/etc/my.cnf.d').with({ end
:ensure => :directory,
:mode => '0755',
})
end
it do context 'service_enabled set to false' do
should contain_file('/etc/my.cnf').with({ let(:params) {{ :service_enabled => false }}
:mode => '0644',
})
end
it do it do
should contain_file('/etc/my.cnf').without_content(/!includedir/) 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 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 end

View file

@ -1,5 +1,10 @@
require 'simplecov'
SimpleCov.start do
add_filter "/spec/"
end
require 'puppetlabs_spec_helper/module_spec_helper' 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(' ')