2013-10-15 23:16:40 +02:00
|
|
|
require 'spec_helper_acceptance'
|
|
|
|
|
2014-07-25 20:32:00 +02:00
|
|
|
describe 'mysql::db define' do
|
2013-10-15 23:16:40 +02:00
|
|
|
describe 'creating a database' do
|
2016-01-18 15:21:51 +01:00
|
|
|
let(:pp) do
|
|
|
|
<<-EOS
|
2013-12-11 00:21:57 +01:00
|
|
|
class { 'mysql::server': root_password => 'password' }
|
2013-10-15 23:16:40 +02:00
|
|
|
mysql::db { 'spec1':
|
|
|
|
user => 'root1',
|
|
|
|
password => 'password',
|
|
|
|
}
|
|
|
|
EOS
|
2016-01-18 15:21:51 +01:00
|
|
|
end
|
|
|
|
it_behaves_like "a idempotent resource"
|
2013-10-15 23:16:40 +02:00
|
|
|
|
2016-01-18 15:21:51 +01:00
|
|
|
describe command("mysql -e 'show databases;'") do
|
|
|
|
its(:exit_status) { is_expected.to eq 0 }
|
|
|
|
its(:stdout) { is_expected.to match /^spec1$/ }
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'creating a database with post-sql' do
|
2016-01-18 15:21:51 +01:00
|
|
|
let(:pp) do
|
|
|
|
<<-EOS
|
2013-10-15 23:16:40 +02:00
|
|
|
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',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
end
|
2016-01-18 15:21:51 +01:00
|
|
|
it_behaves_like "a idempotent resource"
|
2013-10-15 23:16:40 +02:00
|
|
|
|
2016-01-18 15:21:51 +01:00
|
|
|
describe command("mysql -e 'show tables;' spec2") do
|
|
|
|
its(:exit_status) { is_expected.to eq 0 }
|
|
|
|
its(:stdout) { is_expected.to match /^table1$/ }
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|
|
|
|
end
|
2014-03-07 08:08:09 +01:00
|
|
|
|
|
|
|
describe 'creating a database with dbname parameter' do
|
2016-01-18 15:21:51 +01:00
|
|
|
let(:check_command) { " | grep realdb" }
|
|
|
|
let(:pp) do
|
|
|
|
<<-EOS
|
2014-03-07 08:08:09 +01:00
|
|
|
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
|
|
|
mysql::db { 'spec1':
|
|
|
|
user => 'root1',
|
|
|
|
password => 'password',
|
2014-07-25 20:32:00 +02:00
|
|
|
dbname => 'realdb',
|
2014-03-07 08:08:09 +01:00
|
|
|
}
|
|
|
|
EOS
|
|
|
|
end
|
2016-01-18 15:21:51 +01:00
|
|
|
it_behaves_like "a idempotent resource"
|
2014-03-07 08:08:09 +01:00
|
|
|
|
2016-01-18 15:21:51 +01:00
|
|
|
describe command("mysql -e 'show databases;'") do
|
|
|
|
its(:exit_status) { is_expected.to eq 0 }
|
|
|
|
its(:stdout) { is_expected.to match /^realdb$/ }
|
2014-03-07 08:08:09 +01:00
|
|
|
end
|
|
|
|
end
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|