|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe 'mysql::db', :type => :define do |
4 | | - let(:facts) {{ :osfamily => 'RedHat' }} |
5 | | - let(:title) { 'test_db' } |
6 | | - |
7 | | - let(:params) { |
8 | | - { 'user' => 'testuser', |
9 | | - 'password' => 'testpass', |
10 | | - } |
11 | | - } |
12 | | - |
13 | | - it 'should report an error when ensure is not present or absent' do |
14 | | - params.merge!({'ensure' => 'invalid_val'}) |
15 | | - expect { subject }.to raise_error(Puppet::Error, |
16 | | - /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) |
17 | | - end |
| 4 | + on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| |
| 5 | + pe_platforms.each do |pe_platform,facts| |
| 6 | + describe "on #{pe_version} #{pe_platform}" do |
| 7 | + let(:facts) { facts } |
18 | 8 |
|
19 | | - it 'should not notify the import sql exec if no sql script was provided' do |
20 | | - is_expected.to contain_mysql_database('test_db').without_notify |
21 | | - end |
| 9 | + let(:title) { 'test_db' } |
22 | 10 |
|
23 | | - it 'should subscribe to database if sql script is given' do |
24 | | - params.merge!({'sql' => 'test_sql'}) |
25 | | - is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') |
26 | | - end |
| 11 | + let(:params) { |
| 12 | + { 'user' => 'testuser', |
| 13 | + 'password' => 'testpass', |
| 14 | + } |
| 15 | + } |
27 | 16 |
|
28 | | - it 'should only import sql script on creation if not enforcing' do |
29 | | - params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) |
30 | | - is_expected.to contain_exec('test_db-import').with_refreshonly(true) |
31 | | - end |
| 17 | + it 'should report an error when ensure is not present or absent' do |
| 18 | + params.merge!({'ensure' => 'invalid_val'}) |
| 19 | + expect { subject }.to raise_error(Puppet::Error, |
| 20 | + /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) |
| 21 | + end |
32 | 22 |
|
33 | | - it 'should import sql script on creation if enforcing' do |
34 | | - params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) |
35 | | - is_expected.to contain_exec('test_db-import').with_refreshonly(false) |
36 | | - end |
| 23 | + it 'should not notify the import sql exec if no sql script was provided' do |
| 24 | + is_expected.to contain_mysql_database('test_db').without_notify |
| 25 | + end |
37 | 26 |
|
38 | | - it 'should import sql scripts when more than one is specified' do |
39 | | - params.merge!({'sql' => ['test_sql', 'test_2_sql']}) |
40 | | - is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') |
41 | | - end |
| 27 | + it 'should subscribe to database if sql script is given' do |
| 28 | + params.merge!({'sql' => 'test_sql'}) |
| 29 | + is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') |
| 30 | + end |
42 | 31 |
|
43 | | - it 'should not create database and database user' do |
44 | | - params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) |
45 | | - is_expected.to contain_mysql_database('test_db').with_ensure('absent') |
46 | | - is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent') |
47 | | - end |
| 32 | + it 'should only import sql script on creation if not enforcing' do |
| 33 | + params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) |
| 34 | + is_expected.to contain_exec('test_db-import').with_refreshonly(true) |
| 35 | + end |
48 | 36 |
|
49 | | - it 'should create with an appropriate collate and charset' do |
50 | | - params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) |
51 | | - is_expected.to contain_mysql_database('test_db').with({ |
52 | | - 'charset' => 'utf8', |
53 | | - 'collate' => 'utf8_danish_ci', |
54 | | - }) |
55 | | - end |
| 37 | + it 'should import sql script on creation if enforcing' do |
| 38 | + params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) |
| 39 | + is_expected.to contain_exec('test_db-import').with_refreshonly(false) |
| 40 | + is_expected.to contain_exec('test_db-import').with_command("cat test_sql | mysql test_db") |
| 41 | + end |
| 42 | + |
| 43 | + it 'should import sql scripts when more than one is specified' do |
| 44 | + params.merge!({'sql' => ['test_sql', 'test_2_sql']}) |
| 45 | + is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') |
| 46 | + end |
| 47 | + |
| 48 | + it 'should report an error if sql isn\'t a string or an array' do |
| 49 | + params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}}) |
| 50 | + expect { subject }.to raise_error(Puppet::Error, |
| 51 | + /\$sql must be either a string or an array\./) |
| 52 | + end |
| 53 | + |
| 54 | + it 'should not create database and database user' do |
| 55 | + params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) |
| 56 | + is_expected.to contain_mysql_database('test_db').with_ensure('absent') |
| 57 | + is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent') |
| 58 | + end |
| 59 | + |
| 60 | + it 'should create with an appropriate collate and charset' do |
| 61 | + params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) |
| 62 | + is_expected.to contain_mysql_database('test_db').with({ |
| 63 | + 'charset' => 'utf8', |
| 64 | + 'collate' => 'utf8_danish_ci', |
| 65 | + }) |
| 66 | + end |
56 | 67 |
|
57 | | - it 'should use dbname parameter as database name instead of name' do |
58 | | - params.merge!({'dbname' => 'real_db'}) |
59 | | - is_expected.to contain_mysql_database('real_db') |
| 68 | + it 'should use dbname parameter as database name instead of name' do |
| 69 | + params.merge!({'dbname' => 'real_db'}) |
| 70 | + is_expected.to contain_mysql_database('real_db') |
| 71 | + end |
| 72 | + end |
| 73 | + end |
60 | 74 | end |
61 | 75 | end |
0 commit comments