Fix test issues
Remove the dependency on stdlib 4.x puppetlabs/puppetlabs-mysql#574 introduced, add some input validation, and improve test checks.
This commit is contained in:
parent
ab84a671f9
commit
11fb01c736
2 changed files with 66 additions and 47 deletions
|
@ -16,7 +16,12 @@ define mysql::db (
|
||||||
validate_re($ensure, '^(present|absent)$',
|
validate_re($ensure, '^(present|absent)$',
|
||||||
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
||||||
$table = "${dbname}.*"
|
$table = "${dbname}.*"
|
||||||
$sql_inputs = join(any2array($sql), ' ')
|
|
||||||
|
if !(is_array($sql) or is_string($sql)) {
|
||||||
|
fail('$sql must be either a string or an array.')
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_inputs = join([$sql], ' ')
|
||||||
|
|
||||||
include '::mysql::client'
|
include '::mysql::client'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'mysql::db', :type => :define do
|
describe 'mysql::db', :type => :define do
|
||||||
let(:facts) {{ :osfamily => 'RedHat' }}
|
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(:title) { 'test_db' }
|
let(:title) { 'test_db' }
|
||||||
|
|
||||||
let(:params) {
|
let(:params) {
|
||||||
|
@ -33,6 +37,7 @@ describe 'mysql::db', :type => :define do
|
||||||
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")
|
||||||
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
|
||||||
|
@ -40,6 +45,12 @@ describe 'mysql::db', :type => :define do
|
||||||
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
|
||||||
|
params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}})
|
||||||
|
expect { subject }.to raise_error(Puppet::Error,
|
||||||
|
/\$sql must be either a string or an array\./)
|
||||||
|
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')
|
||||||
|
@ -58,4 +69,7 @@ describe 'mysql::db', :type => :define 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
|
||||||
|
|
Loading…
Reference in a new issue