cookbook-openstack-ops-data.../spec/mysql-server_spec.rb

71 lines
2.7 KiB
Ruby

# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-ops-database::mysql-server' do
describe 'ubuntu' do
include_context 'database-stubs'
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set_unless['mysql'] = {
'server_debian_password' => 'server-debian-password',
'server_root_password' => 'server-root-password',
'server_repl_password' => 'server-repl-password'
}
runner.converge(described_recipe)
end
let(:file) { chef_run.template('/etc/mysql/conf.d/openstack.cnf') }
it 'sets mysql version to 5.5' do
expect(chef_run.node['mysql']['version']).to eql '5.5'
end
it 'overrides default mysql attributes' do
expect(chef_run.node['mysql']['tunable']['default-storage-engine']).to eql 'InnoDB'
expect(chef_run.node['mysql']['bind_address']).to eql '127.0.0.1'
expect(chef_run.node['mysql']['tunable']['innodb_thread_concurrency']).to eql '0'
expect(chef_run.node['mysql']['tunable']['innodb_commit_concurrency']).to eql '0'
expect(chef_run.node['mysql']['tunable']['innodb_read_io_threads']).to eql '4'
expect(chef_run.node['mysql']['tunable']['innodb_flush_log_at_trx_commit']).to eql '2'
expect(chef_run.node['mysql']['tunable']['skip-name-resolve']).to eql true
expect(chef_run.node['mysql']['tunable']['character-set-server']).to eql 'utf8'
end
it 'includes mysql recipes' do
expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client'
expect(chef_run).to include_recipe 'mysql::server'
end
it 'creates template /etc/mysql/conf.d/openstack.cnf' do
expect(chef_run).to create_template(file.name).with(
user: 'mysql',
group: 'mysql',
source: 'openstack.cnf.erb'
)
expect(file).to notify('mysql_service[default]')
[/^# This file autogenerated by Chef$/,
/^# Do not edit, changes will be overwritten$/,
/^\[mysqld\]$/,
/^default-storage-engine = InnoDB$/,
/^bind-address = 127.0.0.1$/,
/^innodb_thread_concurrency= 0$/,
/^innodb_commit_concurrency = 0$/,
/^innodb_read_io_threads = 4$/,
/^innodb_flush_log_at_trx_commit = 2$/,
/^skip-name-resolve$/,
/^character-set-server = utf8$/].each do |line|
expect(chef_run).to render_file(file.name).with_content(line)
end
end
it 'prepares the database server' do
expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES')
expect(chef_run).to query_mysql_database('drop empty localhost user')
expect(chef_run).to drop_mysql_database('test')
expect(chef_run).to query_mysql_database('FLUSH PRIVILEGES')
end
end
end