22
33describe 'mysql::db define' do
44 describe 'creating a database' do
5- # Using puppet_apply as a helper
6- it 'should work with no errors' do
7- pp = <<-EOS
5+ let ( :pp ) do
6+ <<-EOS
87 class { 'mysql::server': root_password => 'password' }
98 mysql::db { 'spec1':
109 user => 'root1',
1110 password => 'password',
1211 }
1312 EOS
13+ end
14+ it_behaves_like "a idempotent resource"
1415
15- # Run it twice and test for idempotency
16- apply_manifest ( pp , :catch_failures => true )
17- apply_manifest ( pp , :catch_changes => true )
18-
19- expect ( shell ( "mysql -e 'show databases;'|grep spec1" ) . exit_code ) . to be_zero
16+ describe command ( "mysql -e 'show databases;'" ) do
17+ its ( :exit_status ) { is_expected . to eq 0 }
18+ its ( :stdout ) { is_expected . to match /^spec1$/ }
2019 end
2120 end
2221
2322 describe 'creating a database with post-sql' do
24- # Using puppet_apply as a helper
25- it 'should work with no errors' do
26- pp = <<-EOS
23+ let ( :pp ) do
24+ <<-EOS
2725 class { 'mysql::server': override_options => { 'root_password' => 'password' } }
2826 file { '/tmp/spec.sql':
2927 ensure => file,
@@ -36,36 +34,32 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } }
3634 sql => '/tmp/spec.sql',
3735 }
3836 EOS
39-
40- # Run it twice and test for idempotency
41- apply_manifest ( pp , :catch_failures => true )
42- apply_manifest ( pp , :catch_changes => true )
4337 end
38+ it_behaves_like "a idempotent resource"
4439
45- it 'should have the table' do
46- expect ( shell ( "mysql -e 'show tables;' spec2|grep table1" ) . exit_code ) . to be_zero
40+ describe command ( "mysql -e 'show tables;' spec2" ) do
41+ its ( :exit_status ) { is_expected . to eq 0 }
42+ its ( :stdout ) { is_expected . to match /^table1$/ }
4743 end
4844 end
4945
5046 describe 'creating a database with dbname parameter' do
51- # Using puppet_apply as a helper
52- it 'should work with no errors' do
53- pp = <<-EOS
47+ let ( :check_command ) { " | grep realdb" }
48+ let ( :pp ) do
49+ <<-EOS
5450 class { 'mysql::server': override_options => { 'root_password' => 'password' } }
5551 mysql::db { 'spec1':
5652 user => 'root1',
5753 password => 'password',
5854 dbname => 'realdb',
5955 }
6056 EOS
61-
62- # Run it twice and test for idempotency
63- apply_manifest ( pp , :catch_failures => true )
64- apply_manifest ( pp , :catch_changes => true )
6557 end
58+ it_behaves_like "a idempotent resource"
6659
67- it 'should have the database named realdb' do
68- expect ( shell ( "mysql -e 'show databases;'|grep realdb" ) . exit_code ) . to be_zero
60+ describe command ( "mysql -e 'show databases;'" ) do
61+ its ( :exit_status ) { is_expected . to eq 0 }
62+ its ( :stdout ) { is_expected . to match /^realdb$/ }
6963 end
7064 end
7165end
0 commit comments