(MAINT) switch to rspec-puppet-facts

Switching out the puppet version, as puppet_facts does, does not work,
as this will confuse code that wants to use version-dependent features.

Instead this uses rspec-puppet-facts, which doesn't touch the puppet
version.
This commit is contained in:
David Schmitt 2015-10-13 11:29:42 +01:00
parent 5e6db0bb0f
commit 6527a3aa22
12 changed files with 779 additions and 740 deletions

View file

@ -14,9 +14,9 @@ group :development, :unit_tests do
gem 'rspec-core', '3.1.7', :require => false gem 'rspec-core', '3.1.7', :require => false
gem 'puppetlabs_spec_helper', :require => false gem 'puppetlabs_spec_helper', :require => false
gem 'simplecov', :require => false gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false gem 'json', :require => false
gem 'metadata-json-lint', :require => false gem 'metadata-json-lint', :require => false
gem 'rspec-puppet-facts', :require => false
end end
group :system_tests do group :system_tests do

View file

@ -1,15 +1,19 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server' do describe 'mysql::server' do
on_pe_unsupported_platforms.each do |pe_version,pe_platforms| context "on an unsupported OS" do
pe_platforms.each do |pe_platform,facts| # fetch any sets of facts to modify them
describe "on #{pe_version} #{pe_platform}" do os, facts = on_supported_os.first
let(:facts) { facts }
context 'should gracefully fail' do let(:facts) {
it { expect { is_expected.to compile}.to raise_error(Puppet::Error, /Unsupported platform:/) } facts.merge({
end :osfamily => 'UNSUPPORTED',
end :operatingsystem => 'UNSUPPORTED',
})
}
it 'should gracefully fail' do
is_expected.to compile.and_raise_error(/Unsupported platform:/)
end end
end end
end end

View file

@ -2,76 +2,78 @@ require 'spec_helper'
describe 'mysql::server' do describe 'mysql::server' do
context 'my.cnf template' do context 'my.cnf template' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
context 'normal entry' do context 'normal entry' 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
is_expected.to contain_file('mysql-config-file').with({ is_expected.to contain_file('mysql-config-file').with({
:mode => '0644', :mode => '0644',
:selinux_ignore_defaults => true, :selinux_ignore_defaults => true,
}).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/) }).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/)
end end
end
describe 'array entry' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}}
it do
is_expected.to contain_file('mysql-config-file').with_content(
/.*replicate-do-db = base1\nreplicate-do-db = base2.*/
)
end
end
describe 'ssl set to true' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end
describe 'ssl set to false' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) }
end
# ssl-disable (and ssl) are special cased within mysql.
describe 'possibility of disabling ssl completely' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}}
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end
describe 'a non ssl option set to true' do
let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) }
end
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it 'makes the directory' do
is_expected.to contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end end
describe 'array entry' do it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) }
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}} end
it do
is_expected.to contain_file('mysql-config-file').with_content( context 'without includedir' do
/.*replicate-do-db = base1\nreplicate-do-db = base2.*/ let(:params) {{ :includedir => '' }}
) it 'shouldnt contain the directory' do
end is_expected.not_to contain_file('mysql-config-file').with({
:ensure => :directory,
:mode => '0755',
})
end end
describe 'ssl set to true' do it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) }
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end
describe 'ssl set to false' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) }
end
# ssl-disable (and ssl) are special cased within mysql.
describe 'possibility of disabling ssl completely' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}}
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end
describe 'a non ssl option set to true' do
let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) }
end
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it 'makes the directory' do
is_expected.to contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end
it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) }
end
context 'without includedir' do
let(:params) {{ :includedir => '' }}
it 'shouldnt contain the directory' do
is_expected.not_to contain_file('mysql-config-file').with({
:ensure => :directory,
:mode => '0755',
})
end
it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) }
end
end end
end end
end end

View file

@ -1,30 +1,32 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::bindings' do describe 'mysql::bindings' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
let(:params) {{ let(:params) {{
'java_enable' => true, 'java_enable' => true,
'perl_enable' => true, 'perl_enable' => true,
'php_enable' => true, 'php_enable' => true,
'python_enable' => true, 'python_enable' => true,
'ruby_enable' => true, 'ruby_enable' => true,
'client_dev' => true, 'client_dev' => true,
'daemon_dev' => true, 'daemon_dev' => true,
'client_dev_package_name' => 'libmysqlclient-devel', 'client_dev_package_name' => 'libmysqlclient-devel',
'daemon_dev_package_name' => 'mysql-devel', 'daemon_dev_package_name' => 'mysql-devel',
}} }}
it { is_expected.to contain_package('mysql-connector-java') } it { is_expected.to contain_package('mysql-connector-java') }
it { is_expected.to contain_package('perl_mysql') } it { is_expected.to contain_package('perl_mysql') }
it { is_expected.to contain_package('python-mysqldb') } it { is_expected.to contain_package('python-mysqldb') }
it { is_expected.to contain_package('ruby_mysql') } it { is_expected.to contain_package('ruby_mysql') }
it { is_expected.to contain_package('mysql-client_dev') } it { is_expected.to contain_package('mysql-client_dev') }
it { is_expected.to contain_package('mysql-daemon_dev') } it { is_expected.to contain_package('mysql-daemon_dev') }
end
end end
end end
end end

View file

@ -1,36 +1,38 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::client' do describe 'mysql::client' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
context 'with defaults' do })
it { is_expected.not_to contain_class('mysql::bindings') } }
it { is_expected.to contain_package('mysql_client') }
end
context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }}
it { is_expected.to contain_class('mysql::bindings') }
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to true' do
let(:params) {{ :package_manage => true }}
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to false' do
let(:params) {{ :package_manage => false }}
it { is_expected.not_to contain_package('mysql_client') }
end
context 'with defaults' do
it { is_expected.not_to contain_class('mysql::bindings') }
it { is_expected.to contain_package('mysql_client') }
end end
context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }}
it { is_expected.to contain_class('mysql::bindings') }
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to true' do
let(:params) {{ :package_manage => true }}
it { is_expected.to contain_package('mysql_client') }
end
context 'with package_manage set to false' do
let(:params) {{ :package_manage => false }}
it { is_expected.not_to contain_package('mysql_client') }
end
end end
end end
end end

View file

@ -1,10 +1,16 @@
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| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do context "with fqdn==myhost.mydomain" do
let(:facts) { facts.merge({:fqdn => 'myhost.mydomain', :hostname => 'myhost'}) } let(:facts) {
facts.merge({
:root_home => '/root',
:fqdn => 'myhost.mydomain',
:hostname => 'myhost',
})
}
[ 'root@myhost.mydomain', [ 'root@myhost.mydomain',
'root@127.0.0.1', 'root@127.0.0.1',
@ -32,8 +38,14 @@ describe 'mysql::server::account_security' do
end end
end end
describe "on #{pe_version} #{pe_platform} with fqdn==localhost" do context "with fqdn==localhost" do
let(:facts) { facts.merge({:fqdn => 'localhost', :hostname => 'localhost'}) } let(:facts) {
facts.merge({
:root_home => '/root',
:fqdn => 'localhost',
:hostname => 'localhost',
})
}
[ 'root@127.0.0.1', [ 'root@127.0.0.1',
'root@::1', 'root@::1',
@ -48,8 +60,14 @@ describe 'mysql::server::account_security' do
end end
end end
describe "on #{pe_version} #{pe_platform} with fqdn==localhost.localdomain" do context "with fqdn==localhost.localdomain" do
let(:facts) { facts.merge({:fqdn => 'localhost.localdomain', :hostname => 'localhost'}) } let(:facts) {
facts.merge({
:root_home => '/root',
:fqdn => 'localhost.localdomain',
:hostname => 'localhost',
})
}
[ 'root@127.0.0.1', [ 'root@127.0.0.1',
'root@::1', 'root@::1',

View file

@ -1,401 +1,403 @@
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| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
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 }
# Cannot use that_requires here, doesn't work on classes.
it { is_expected.to contain_mysql_user('testuser@localhost').with(
:require => 'Class[Mysql::Server::Root_password]') }
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS']
).that_requires('Mysql_user[testuser@localhost]') }
context 'with triggers included' do
let(:params) do
{ :include_triggers => true }.merge(default_params)
end
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER']
).that_requires('Mysql_user[testuser@localhost]') }
end
it { is_expected.to contain_cron('mysql-backup').with(
:command => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
)}
it { is_expected.to contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
it { is_expected.to contain_file('mysqlbackupdir').with(
:path => '/tmp',
:ensure => 'directory'
)}
it 'should have compression by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/bzcat -zc/
)
end
it 'should skip backing up events table by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="--ignore-table=mysql.event"/
)
end
it 'should not mention triggers by default because file_per_database is false' do
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*triggers.*/
)
end
it 'should not mention routines by default because file_per_database is false' do
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*routines.*/
)
end
it 'should have 25 days of rotation' do
# MySQL counts from 0
is_expected.to contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/)
end
it 'should have a standard PATH' do
is_expected.to contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin})
end
end
context 'custom ownership and mode for backupdir' do
let(:params) do
{ :backupdirmode => '0750',
:backupdirowner => 'testuser',
:backupdirgroup => 'testgrp',
}.merge(default_params)
end
it { is_expected.to contain_file('mysqlbackupdir').with(
:path => '/tmp',
:ensure => 'directory',
:mode => '0750',
:owner => 'testuser',
:group => 'testgrp'
) }
end
context 'with compression disabled' do
let(:params) do
{ :backupcompress => false }.merge(default_params)
end
it { is_expected.to contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
it 'should be able to disable compression' do
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*bzcat -zc.*/
)
end
end
context 'with mysql.events backedup' do
let(:params) do
{ :ignore_events => false }.merge(default_params)
end
it { is_expected.to contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
it 'should be able to backup events table' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="--events"/
)
end
end
context 'with database list specified' do
let(:params) do
{ :backupdatabases => ['mysql'] }.merge(default_params)
end
it { is_expected.to contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
)
} }
context 'standard conditions' do it 'should have a backup file for each database' do
let(:params) { default_params } is_expected.to contain_file('mysqlbackup.sh').with_content(
/mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date'/
)
end
# Cannot use that_requires here, doesn't work on classes. it 'should skip backup triggers by default' do
it { is_expected.to contain_mysql_user('testuser@localhost').with( is_expected.to contain_file('mysqlbackup.sh').with_content(
:require => 'Class[Mysql::Server::Root_password]') } /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
)
end
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with( it 'should skip backing up routines by default' do
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS'] is_expected.to contain_file('mysqlbackup.sh').with_content(
).that_requires('Mysql_user[testuser@localhost]') } /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
context 'with triggers included' do context 'with include_triggers set to true' do
let(:params) do let(:params) do
{ :include_triggers => true }.merge(default_params) default_params.merge({
end :backupdatabases => ['mysql'],
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with( :include_triggers => true
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER'] })
).that_requires('Mysql_user[testuser@localhost]') }
end end
it { is_expected.to contain_cron('mysql-backup').with( it 'should backup triggers when asked' do
:command => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
)}
it { is_expected.to contain_file('mysqlbackup.sh').with(
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
it { is_expected.to contain_file('mysqlbackupdir').with(
:path => '/tmp',
:ensure => 'directory'
)}
it 'should have compression by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('mysqlbackup.sh').with_content(
/bzcat -zc/ /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
) )
end end
it 'should skip backing up events table by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="--ignore-table=mysql.event"/
)
end
it 'should not mention triggers by default because file_per_database is false' do
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*triggers.*/
)
end
it 'should not mention routines by default because file_per_database is false' do
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*routines.*/
)
end
it 'should have 25 days of rotation' do
# MySQL counts from 0
is_expected.to contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/)
end
it 'should have a standard PATH' do
is_expected.to 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 context 'with include_triggers set to false' do
let(:params) do let(:params) do
{ :backupdirmode => '0750', default_params.merge({
:backupdirowner => 'testuser', :backupdatabases => ['mysql'],
:backupdirgroup => 'testgrp', :include_triggers => false
}.merge(default_params) })
end end
it { is_expected.to contain_file('mysqlbackupdir').with( it 'should skip backing up triggers when asked to skip' do
:path => '/tmp', is_expected.to contain_file('mysqlbackup.sh').with_content(
:ensure => 'directory', /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
:mode => '0750', )
:owner => 'testuser', end
:group => 'testgrp' end
) }
context 'with include_routines set to true' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_routines => true
})
end
it 'should backup routines when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/
)
end
end
context 'with include_routines set to false' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_triggers => true
})
end
it 'should skip backing up routines when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
end
end
context 'with file per database' do
let(:params) do
default_params.merge({ :file_per_database => true })
end
it 'should loop through backup all databases' do
is_expected.to contain_file('mysqlbackup.sh').with_content(/.*SHOW DATABASES.*/)
end end
context 'with compression disabled' do context 'with compression disabled' do
let(:params) do let(:params) do
{ :backupcompress => false }.merge(default_params) default_params.merge({ :file_per_database => true, :backupcompress => false })
end end
it { is_expected.to contain_file('mysqlbackup.sh').with( it 'should loop through backup all databases without compression' do
:path => '/usr/local/sbin/mysqlbackup.sh', is_expected.to contain_file('mysqlbackup.sh').with_content(
:ensure => 'present' /.*SHOW DATABASES.*/
) } )
it 'should be able to disable compression' do
is_expected.to contain_file('mysqlbackup.sh').without_content( is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*bzcat -zc.*/ /.*bzcat -zc.*/
) )
end end
end end
context 'with mysql.events backedup' do it 'should skip backup triggers by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
)
end
it 'should skip backing up routines by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
context 'with include_triggers set to true' do
let(:params) do let(:params) do
{ :ignore_events => false }.merge(default_params) default_params.merge({
:file_per_database => true,
:include_triggers => true
})
end end
it { is_expected.to contain_file('mysqlbackup.sh').with( it 'should backup triggers when asked' do
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
) }
it 'should be able to backup events table' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="--events"/ /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
) )
end end
end end
context 'with database list specified' do context 'with include_triggers set to false' do
let(:params) do let(:params) do
{ :backupdatabases => ['mysql'] }.merge(default_params) default_params.merge({
:file_per_database => true,
:include_triggers => false
})
end end
it { is_expected.to contain_file('mysqlbackup.sh').with( it 'should skip backing up triggers when asked to skip' do
:path => '/usr/local/sbin/mysqlbackup.sh',
:ensure => 'present'
)
}
it 'should have a backup file for each database' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date'/
)
end
it 'should skip backup triggers by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
) )
end end
it 'should skip backing up routines by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
context 'with include_triggers set to true' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_triggers => true
})
end
it 'should backup triggers when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
)
end
end
context 'with include_triggers set to false' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_triggers => false
})
end
it 'should skip backing up triggers when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
)
end
end
context 'with include_routines set to true' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_routines => true
})
end
it 'should backup routines when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/
)
end
end
context 'with include_routines set to false' do
let(:params) do
default_params.merge({
:backupdatabases => ['mysql'],
:include_triggers => true
})
end
it 'should skip backing up routines when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
end
end end
context 'with file per database' do context 'with include_routines set to true' do
let(:params) do let(:params) do
default_params.merge({ :file_per_database => true }) default_params.merge({
:file_per_database => true,
:include_routines => true
})
end end
it 'should loop through backup all databases' do it 'should backup routines when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(/.*SHOW DATABASES.*/)
end
context 'with compression disabled' do
let(:params) do
default_params.merge({ :file_per_database => true, :backupcompress => false })
end
it 'should loop through backup all databases without compression' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/.*SHOW DATABASES.*/
)
is_expected.to contain_file('mysqlbackup.sh').without_content(
/.*bzcat -zc.*/
)
end
end
it 'should skip backup triggers by default' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/
) )
end end
end
it 'should skip backing up routines by default' do context 'with include_routines set to false' do
let(:params) do
default_params.merge({
:file_per_database => true,
:include_triggers => true
})
end
it 'should skip backing up routines when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/ /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
) )
end end
end
end
context 'with include_triggers set to true' do context 'with postscript' do
let(:params) do let(:params) do
default_params.merge({ default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' })
:file_per_database => true,
:include_triggers => true
})
end
it 'should backup triggers when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
)
end
end
context 'with include_triggers set to false' do
let(:params) do
default_params.merge({
:file_per_database => true,
:include_triggers => false
})
end
it 'should skip backing up triggers when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/
)
end
end
context 'with include_routines set to true' do
let(:params) do
default_params.merge({
:file_per_database => true,
:include_routines => true
})
end
it 'should backup routines when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/
)
end
end
context 'with include_routines set to false' do
let(:params) do
default_params.merge({
:file_per_database => true,
:include_triggers => true
})
end
it 'should skip backing up routines when asked to skip' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/
)
end
end
end end
context 'with postscript' do it 'should be add postscript' do
let(:params) do is_expected.to contain_file('mysqlbackup.sh').with_content(
default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' }) /rsync -a \/tmp backup01.local-lan:/
end )
end
end
it 'should be add postscript' do context 'with postscripts' do
is_expected.to contain_file('mysqlbackup.sh').with_content( let(:params) do
/rsync -a \/tmp backup01.local-lan:/ default_params.merge({ :postscript => [
) 'rsync -a /tmp backup01.local-lan:',
end 'rsync -a /tmp backup02.local-lan:',
]})
end end
context 'with postscripts' do it 'should be add postscript' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
)
end
end
context 'with the xtrabackup provider' do
let(:params) do
default_params.merge({:provider => 'xtrabackup'})
end
it 'should contain the wrapper script' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/^innobackupex\s+"\$@"/
)
end
context 'with prescript defined' do
let(:params) do let(:params) do
default_params.merge({ :postscript => [ default_params.merge({
'rsync -a /tmp backup01.local-lan:', :provider => 'xtrabackup',
'rsync -a /tmp backup02.local-lan:', :prescript => [
]}) 'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end end
it 'should be add postscript' do it 'should contain the prescript' do
is_expected.to contain_file('mysqlbackup.sh').with_content( is_expected.to contain_file('xtrabackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/ /.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
) )
end end
end end
context 'with the xtrabackup provider' do context 'with postscript defined' do
let(:params) do let(:params) do
default_params.merge({:provider => 'xtrabackup'}) default_params.merge({
:provider => 'xtrabackup',
:postscript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end end
it 'should contain the wrapper script' do it 'should contain the prostscript' do
is_expected.to contain_file('xtrabackup.sh').with_content( is_expected.to contain_file('xtrabackup.sh').with_content(
/^innobackupex\s+"\$@"/ /.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
) )
end end
context 'with prescript defined' do
let(:params) do
default_params.merge({
:provider => 'xtrabackup',
:prescript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end
it 'should contain the prescript' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
)
end
end
context 'with postscript defined' do
let(:params) do
default_params.merge({
:provider => 'xtrabackup',
:postscript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end
it 'should contain the prostscript' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
)
end
end
end end
end end
end end

View file

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

View file

@ -1,42 +1,44 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server::mysqltuner' do describe 'mysql::server::mysqltuner' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
context 'ensure => present' do context 'ensure => present' do
it { is_expected.to compile } it { is_expected.to compile }
it { is_expected.to contain_staging__file('mysqltuner-v1.3.0').with({ it { is_expected.to contain_staging__file('mysqltuner-v1.3.0').with({
:source => 'https://github.com/major/MySQLTuner-perl/raw/v1.3.0/mysqltuner.pl', :source => 'https://github.com/major/MySQLTuner-perl/raw/v1.3.0/mysqltuner.pl',
}) })
} }
end end
context 'ensure => absent' do context 'ensure => absent' do
let(:params) {{ :ensure => 'absent' }} let(:params) {{ :ensure => 'absent' }}
it { is_expected.to compile } it { is_expected.to compile }
it { is_expected.to contain_file('/usr/local/bin/mysqltuner').with(:ensure => 'absent') } it { is_expected.to contain_file('/usr/local/bin/mysqltuner').with(:ensure => 'absent') }
end end
context 'custom version' do context 'custom version' do
let(:params) {{ :version => 'v1.2.0' }} let(:params) {{ :version => 'v1.2.0' }}
it { is_expected.to compile } it { is_expected.to compile }
it { is_expected.to contain_staging__file('mysqltuner-v1.2.0').with({ it { is_expected.to contain_staging__file('mysqltuner-v1.2.0').with({
:source => 'https://github.com/major/MySQLTuner-perl/raw/v1.2.0/mysqltuner.pl', :source => 'https://github.com/major/MySQLTuner-perl/raw/v1.2.0/mysqltuner.pl',
}) })
} }
end end
context 'custom source' do context 'custom source' do
let(:params) {{ :source => '/tmp/foo' }} let(:params) {{ :source => '/tmp/foo' }}
it { is_expected.to compile } it { is_expected.to compile }
it { is_expected.to contain_staging__file('mysqltuner-/tmp/foo').with({ it { is_expected.to contain_staging__file('mysqltuner-/tmp/foo').with({
:source => '/tmp/foo', :source => '/tmp/foo',
}) })
} }
end
end end
end end
end end

View file

@ -1,190 +1,192 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::server' do describe 'mysql::server' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
context 'with defaults' do
it { is_expected.to contain_class('mysql::server::install') }
it { is_expected.to contain_class('mysql::server::config') }
it { is_expected.to contain_class('mysql::server::service') }
it { is_expected.to contain_class('mysql::server::root_password') }
it { is_expected.to contain_class('mysql::server::providers') }
end
context 'with remove_default_accounts set' do
let(:params) {{ :remove_default_accounts => true }}
it { is_expected.to contain_class('mysql::server::account_security') }
end
context 'when not managing config file' do
let(:params) {{ :manage_config_file => false }}
it { is_expected.to compile.with_all_deps }
end
context 'mysql::server::install' do
it 'contains the package by default' do
is_expected.to contain_package('mysql-server').with({
:ensure => :present,
})
end
context 'with package_manage set to true' do
let(:params) {{ :package_manage => true }}
it { is_expected.to contain_package('mysql-server') }
end
context 'with package_manage set to false' do
let(:params) {{ :package_manage => false }}
it { is_expected.not_to contain_package('mysql-server') }
end
context 'with datadir overridden' do
let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }}
it { is_expected.to contain_exec('mysql_install_db') }
end
end
context 'mysql::server::service' do
context 'with defaults' do context 'with defaults' do
it { is_expected.to contain_class('mysql::server::install') } it { is_expected.to contain_service('mysqld') }
it { is_expected.to contain_class('mysql::server::config') }
it { is_expected.to contain_class('mysql::server::service') }
it { is_expected.to contain_class('mysql::server::root_password') }
it { is_expected.to contain_class('mysql::server::providers') }
end end
context 'with package_manage set to true' do
context 'with remove_default_accounts set' do let(:params) {{ :package_manage => true }}
let(:params) {{ :remove_default_accounts => true }} it { is_expected.to contain_service('mysqld').that_requires('Package[mysql-server]') }
it { is_expected.to contain_class('mysql::server::account_security') }
end end
context 'with package_manage set to false' do
context 'when not managing config file' do let(:params) {{ :package_manage => false }}
let(:params) {{ :manage_config_file => false }} it { is_expected.to contain_service('mysqld') }
it { is_expected.to compile.with_all_deps } it { is_expected.not_to contain_service('mysqld').that_requires('Package[mysql-server]') }
end end
context 'service_enabled set to false' do
let(:params) {{ :service_enabled => false }}
context 'mysql::server::install' do it do
it 'contains the package by default' do is_expected.to contain_service('mysqld').with({
is_expected.to contain_package('mysql-server').with({ :ensure => :stopped
:ensure => :present,
}) })
end end
context 'with package_manage set to true' do end
let(:params) {{ :package_manage => true }} context 'with log-error overridden' do
it { is_expected.to contain_package('mysql-server') } let(:params) {{ :override_options => { 'mysqld' => { 'log-error' => '/tmp/error.log' }} }}
end it { is_expected.to contain_file('/tmp/error.log') }
context 'with package_manage set to false' do end
let(:params) {{ :package_manage => false }} end
it { is_expected.not_to contain_package('mysql-server') }
end context 'mysql::server::root_password' do
context 'with datadir overridden' do describe 'when defaults' do
let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }} it {
it { is_expected.to contain_exec('mysql_install_db') } is_expected.to contain_exec('remove install pass').with(
end :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret',
:onlyif => 'test -f /.mysql_secret',
:path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
)
}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.not_to contain_file('/root/.my.cnf') }
end
describe 'when root_password set' do
let(:params) {{:root_password => 'SET' }}
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
end
describe 'when root_password set, create_root_user set to false' do
let(:params) {{ :root_password => 'SET', :create_root_user => false }}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf') }
end
describe 'when root_password set, create_root_my_cnf set to false' do
let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }}
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.not_to contain_file('/root/.my.cnf') }
end
describe 'when root_password set, create_root_user and create_root_my_cnf set to false' do
let(:params) {{ :root_password => 'SET', :create_root_user => false, :create_root_my_cnf => false }}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.not_to contain_file('/root/.my.cnf') }
end
describe 'when install_secret_file set to /root/.mysql_secret' do
let(:params) {{ :install_secret_file => '/root/.mysql_secret' }}
it {
is_expected.to contain_exec('remove install pass').with(
:command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret',
:onlyif => 'test -f /root/.mysql_secret'
)
}
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 { is_expected.to 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 { is_expected.to 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 => nil
)}
end end
context 'mysql::server::service' do describe 'with grants' do
context 'with defaults' do let(:params) {{:grants => {
it { is_expected.to contain_service('mysqld') } 'foo@localhost/somedb.*' => {
end 'user' => 'foo@localhost',
context 'with package_manage set to true' do 'table' => 'somedb.*',
let(:params) {{ :package_manage => true }} 'privileges' => ["SELECT", "UPDATE"],
it { is_expected.to contain_service('mysqld').that_requires('Package[mysql-server]') } 'options' => ["GRANT"],
end },
context 'with package_manage set to false' do 'foo2@localhost/*.*' => {
let(:params) {{ :package_manage => false }} 'user' => 'foo2@localhost',
it { is_expected.to contain_service('mysqld') } 'table' => '*.*',
it { is_expected.not_to contain_service('mysqld').that_requires('Package[mysql-server]') } 'privileges' => ["SELECT"],
end },
context 'service_enabled set to false' do }}}
let(:params) {{ :service_enabled => false }} it { is_expected.to contain_mysql_grant('foo@localhost/somedb.*').with(
:user => 'foo@localhost',
it do :table => 'somedb.*',
is_expected.to contain_service('mysqld').with({ :privileges => ["SELECT", "UPDATE"],
:ensure => :stopped :options => ["GRANT"]
}) )}
end it { is_expected.to contain_mysql_grant('foo2@localhost/*.*').with(
end :user => 'foo2@localhost',
context 'with log-error overridden' do :table => '*.*',
let(:params) {{ :override_options => { 'mysqld' => { 'log-error' => '/tmp/error.log' }} }} :privileges => ["SELECT"],
it { is_expected.to contain_file('/tmp/error.log') } :options => nil
end )}
end end
context 'mysql::server::root_password' do describe 'with databases' do
describe 'when defaults' do let(:params) {{:databases => {
it { 'somedb' => {
is_expected.to contain_exec('remove install pass').with( 'charset' => 'latin1',
:command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret', 'collate' => 'latin1',
:onlyif => 'test -f /.mysql_secret', },
:path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' 'somedb2' => {}
) }}}
} it { is_expected.to contain_mysql_database('somedb').with(
it { is_expected.not_to contain_mysql_user('root@localhost') } :charset => 'latin1',
it { is_expected.not_to contain_file('/root/.my.cnf') } :collate => 'latin1'
end )}
describe 'when root_password set' do it { is_expected.to contain_mysql_database('somedb2')}
let(:params) {{:root_password => 'SET' }}
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
end
describe 'when root_password set, create_root_user set to false' do
let(:params) {{ :root_password => 'SET', :create_root_user => false }}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf') }
end
describe 'when root_password set, create_root_my_cnf set to false' do
let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }}
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.not_to contain_file('/root/.my.cnf') }
end
describe 'when root_password set, create_root_user and create_root_my_cnf set to false' do
let(:params) {{ :root_password => 'SET', :create_root_user => false, :create_root_my_cnf => false }}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.not_to contain_file('/root/.my.cnf') }
end
describe 'when install_secret_file set to /root/.mysql_secret' do
let(:params) {{ :install_secret_file => '/root/.mysql_secret' }}
it {
is_expected.to contain_exec('remove install pass').with(
:command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret',
:onlyif => 'test -f /root/.mysql_secret'
)
}
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 { is_expected.to 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 { is_expected.to 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 => nil
)}
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 { is_expected.to contain_mysql_grant('foo@localhost/somedb.*').with(
:user => 'foo@localhost',
:table => 'somedb.*',
:privileges => ["SELECT", "UPDATE"],
:options => ["GRANT"]
)}
it { is_expected.to 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 { is_expected.to contain_mysql_database('somedb').with(
:charset => 'latin1',
:collate => 'latin1'
)}
it { is_expected.to contain_mysql_database('somedb2')}
end
end end
end end
end end

View file

@ -1,74 +1,76 @@
require 'spec_helper' require 'spec_helper'
describe 'mysql::db', :type => :define do describe 'mysql::db', :type => :define do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| on_supported_os.each do |os, facts|
pe_platforms.each do |pe_platform,facts| context "on #{os}" do
describe "on #{pe_version} #{pe_platform}" do let(:facts) {
let(:facts) { facts } facts.merge({
:root_home => '/root',
})
}
let(:title) { 'test_db' } let(:title) { 'test_db' }
let(:params) { let(:params) {
{ 'user' => 'testuser', { 'user' => 'testuser',
'password' => 'testpass', 'password' => 'testpass',
}
} }
}
it 'should report an error when ensure is not present or absent' do it 'should report an error when ensure is not present or absent' do
params.merge!({'ensure' => 'invalid_val'}) params.merge!({'ensure' => 'invalid_val'})
expect { catalogue }.to raise_error(Puppet::Error, expect { catalogue }.to raise_error(Puppet::Error,
/invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./)
end end
it 'should not notify the import sql exec if no sql script was provided' do it 'should not notify the import sql exec if no sql script was provided' do
is_expected.to contain_mysql_database('test_db').without_notify is_expected.to contain_mysql_database('test_db').without_notify
end end
it 'should subscribe to database if sql script is given' do it 'should subscribe to database if sql script is given' do
params.merge!({'sql' => 'test_sql'}) params.merge!({'sql' => 'test_sql'})
is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]')
end end
it 'should only import sql script on creation if not enforcing' do it 'should only import sql script on creation if not enforcing' do
params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) params.merge!({'sql' => 'test_sql', 'enforce_sql' => false})
is_expected.to contain_exec('test_db-import').with_refreshonly(true) is_expected.to contain_exec('test_db-import').with_refreshonly(true)
end end
it 'should import sql script on creation if enforcing' do it 'should import sql script on creation if enforcing' do
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) params.merge!({'sql' => 'test_sql', 'enforce_sql' => true})
is_expected.to contain_exec('test_db-import').with_refreshonly(false) is_expected.to contain_exec('test_db-import').with_refreshonly(false)
is_expected.to contain_exec('test_db-import').with_command("cat test_sql | mysql test_db") is_expected.to contain_exec('test_db-import').with_command("cat test_sql | mysql test_db")
end end
it 'should import sql scripts when more than one is specified' do it 'should import sql scripts when more than one is specified' do
params.merge!({'sql' => ['test_sql', 'test_2_sql']}) params.merge!({'sql' => ['test_sql', 'test_2_sql']})
is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db')
end end
it 'should report an error if sql isn\'t a string or an array' do it 'should report an error if sql isn\'t a string or an array' do
params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}}) params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}})
expect { catalogue }.to raise_error(Puppet::Error, expect { catalogue }.to raise_error(Puppet::Error,
/\$sql must be either a string or an array\./) /\$sql must be either a string or an array\./)
end end
it 'should not create database and database user' do it 'should not create database and database user' do
params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) params.merge!({'ensure' => 'absent', 'host' => 'localhost'})
is_expected.to contain_mysql_database('test_db').with_ensure('absent') is_expected.to contain_mysql_database('test_db').with_ensure('absent')
is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent') is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent')
end end
it 'should create with an appropriate collate and charset' do it 'should create with an appropriate collate and charset' do
params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'})
is_expected.to contain_mysql_database('test_db').with({ is_expected.to contain_mysql_database('test_db').with({
'charset' => 'utf8', 'charset' => 'utf8',
'collate' => 'utf8_danish_ci', 'collate' => 'utf8_danish_ci',
}) })
end end
it 'should use dbname parameter as database name instead of name' do it 'should use dbname parameter as database name instead of name' do
params.merge!({'dbname' => 'real_db'}) params.merge!({'dbname' => 'real_db'})
is_expected.to contain_mysql_database('real_db') is_expected.to contain_mysql_database('real_db')
end
end end
end end
end end

View file

@ -1,6 +1,6 @@
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
require 'puppet_facts' require 'rspec-puppet-facts'
include PuppetFacts include RspecPuppetFacts
# The default set of platforms to test again. # The default set of platforms to test again.
ENV['UNIT_TEST_PLATFORMS'] = 'centos-6-x86_64 ubuntu-1404-x86_64' ENV['UNIT_TEST_PLATFORMS'] = 'centos-6-x86_64 ubuntu-1404-x86_64'