2
2
3
3
describe 'mysql::db define' do
4
4
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
8
7
class { 'mysql::server': root_password => 'password' }
9
8
mysql::db { 'spec1':
10
9
user => 'root1',
11
10
password => 'password',
12
11
}
13
12
EOS
13
+ end
14
+ it_behaves_like "a idempotent resource"
14
15
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$/ }
20
19
end
21
20
end
22
21
23
22
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
27
25
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
28
26
file { '/tmp/spec.sql':
29
27
ensure => file,
@@ -36,36 +34,32 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } }
36
34
sql => '/tmp/spec.sql',
37
35
}
38
36
EOS
39
-
40
- # Run it twice and test for idempotency
41
- apply_manifest ( pp , :catch_failures => true )
42
- apply_manifest ( pp , :catch_changes => true )
43
37
end
38
+ it_behaves_like "a idempotent resource"
44
39
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$/ }
47
43
end
48
44
end
49
45
50
46
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
54
50
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
55
51
mysql::db { 'spec1':
56
52
user => 'root1',
57
53
password => 'password',
58
54
dbname => 'realdb',
59
55
}
60
56
EOS
61
-
62
- # Run it twice and test for idempotency
63
- apply_manifest ( pp , :catch_failures => true )
64
- apply_manifest ( pp , :catch_changes => true )
65
57
end
58
+ it_behaves_like "a idempotent resource"
66
59
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$/ }
69
63
end
70
64
end
71
65
end
0 commit comments