Skip to content

Commit 8386374

Browse files
authored
Merge pull request #930 from bastelfreak/puppet4
replace validate_* with datatypes in db.pp
2 parents 4fc16bc + 437dcb9 commit 8386374

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

manifests/db.pp

+10-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22
define mysql::db (
33
$user,
44
$password,
5-
$dbname = $name,
6-
$charset = 'utf8',
7-
$collate = 'utf8_general_ci',
8-
$host = 'localhost',
9-
$grant = 'ALL',
10-
$sql = undef,
11-
$enforce_sql = false,
12-
$ensure = 'present',
13-
$import_timeout = 300,
14-
$import_cat_cmd = 'cat',
5+
$dbname = $name,
6+
$charset = 'utf8',
7+
$collate = 'utf8_general_ci',
8+
$host = 'localhost',
9+
$grant = 'ALL',
10+
Optional[Variant[Array, Hash, String]] $sql = undef,
11+
$enforce_sql = false,
12+
Enum['absent', 'present'] $ensure = 'present',
13+
$import_timeout = 300,
14+
$import_cat_cmd = 'cat',
1515
) {
1616
#input validation
17-
validate_re($ensure, '^(present|absent)$',
18-
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
1917
$table = "${dbname}.*"
2018

21-
if !(is_array($sql) or is_string($sql)) {
22-
fail('$sql must be either a string or an array.')
23-
}
24-
2519
$sql_inputs = join([$sql], ' ')
2620

2721
include '::mysql::client'

metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"requirements": [
7373
{
7474
"name": "puppet",
75-
"version_requirement": ">= 3.0.0 < 5.0.0"
75+
"version_requirement": ">= 4.7.0 < 5.0.0"
7676
}
7777
],
7878
"description": "MySQL module"

spec/defines/mysql_db_spec.rb

-12
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
}
1818
}
1919

20-
it 'should report an error when ensure is not present or absent' do
21-
params.merge!({'ensure' => 'invalid_val'})
22-
expect { catalogue }.to raise_error(Puppet::Error,
23-
/invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./)
24-
end
25-
2620
it 'should not notify the import sql exec if no sql script was provided' do
2721
is_expected.to contain_mysql_database('test_db').without_notify
2822
end
@@ -54,12 +48,6 @@
5448
is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db')
5549
end
5650

57-
it 'should report an error if sql isn\'t a string or an array' do
58-
params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}})
59-
expect { catalogue }.to raise_error(Puppet::Error,
60-
/\$sql must be either a string or an array\./)
61-
end
62-
6351
it 'should not create database and database user' do
6452
params.merge!({'ensure' => 'absent', 'host' => 'localhost'})
6553
is_expected.to contain_mysql_database('test_db').with_ensure('absent')

spec/unit/puppet/functions/mysql_deepmerge_spec.rb

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
end
2525

2626
describe 'when calling mysql_deepmerge on the scope instance' do
27-
it 'should require all parameters are hashes' do
28-
expect { new_hash = scope.function_mysql_deepmerge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
29-
expect { new_hash = scope.function_mysql_deepmerge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/)
30-
end
31-
3227
it 'should accept empty strings as puppet undef' do
3328
expect { new_hash = scope.function_mysql_deepmerge([{}, ''])}.not_to raise_error
3429
end

0 commit comments

Comments
 (0)