-
Notifications
You must be signed in to change notification settings - Fork 794
/
Copy pathmysql_db_spec.rb
81 lines (72 loc) · 2.09 KB
/
mysql_db_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'spec_helper_acceptance'
describe 'mysql::db define' do
describe 'creating a database' do
let(:pp) do
<<-MANIFEST
class { 'mysql::server':
root_password => 'password',
service_enabled => 'true',
service_manage => 'true',
}
mysql::db { 'spec1':
user => 'root1',
password => 'password',
}
MANIFEST
end
it 'behaves idempotently' do
idempotent_apply(pp)
end
it 'Checking exit code and stdout' do
result = run_shell("mysql -e 'show databases;'")
expect(result.exit_code).to eq 0
expect(result.stdout).to match %r{^spec1$}
end
end
describe 'creating a database with post-sql' do
let(:pp) do
<<-MANIFEST
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
file { '/tmp/spec.sql':
ensure => file,
content => 'CREATE TABLE table1 (id int);',
before => Mysql::Db['spec2'],
}
mysql::db { 'spec2':
user => 'root1',
password => 'password',
sql => '/tmp/spec.sql',
}
MANIFEST
end
it 'behaves idempotently' do
idempotent_apply(pp)
end
it 'Checking exit code and stdout' do
result = run_shell("mysql -e 'show tables;' spec2")
expect(result.exit_code).to eq 0
expect(result.stdout).to match %r{^table1$}
end
end
describe 'creating a database with dbname parameter' do
let(:check_command) { ' | grep realdb' }
let(:pp) do
<<-MANIFEST
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
mysql::db { 'spec1':
user => 'root1',
password => 'password',
dbname => 'realdb',
}
MANIFEST
end
it 'behaves idempotently' do
idempotent_apply(pp)
end
it 'Checking exit code and stdout' do
result = run_shell("mysql -e 'show databases;'")
expect(result.exit_code).to eq 0
expect(result.stdout).to match %r{^realdb$}
end
end
end