cookbook-openstack-common/spec/database_spec.rb
Chen Zhiwei f0e55b8742 Add database charset during create
When using MySQL, the database charset should be utf-8.

And the default charset is latin1, which will cause glance db sync
failed.

Closes-bug: #1356887
Change-Id: I50e299410de8068150d1c405994ecb96918fbc7d
2014-08-20 00:26:24 +00:00

56 lines
1.7 KiB
Ruby

# encoding: UTF-8
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'database'
describe 'openstack-common::default' do
describe 'Openstack Database' do
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) }
let(:subject) { Object.new.extend(Openstack) }
include_context 'library-stubs'
describe '#db_create_with_user' do
before do
allow(subject).to receive(:include_recipe)
.with('database::mysql')
.and_return('')
end
it 'returns nil when no such service was found' do
expect(
subject.db_create_with_user('nonexisting', 'user', 'pass')
).to be_nil
end
it 'returns db info and creates database with user when service found' do
['mysql', 'pgsql', 'postgresql'].each do |db_type|
encoding = node['openstack']['db']['charset'][db_type]
if encoding.nil?
allow(subject).to receive(:database).and_return({})
else
allow(subject).to receive(:database).with(encoding: encoding).and_return({})
end
end
allow(subject).to receive(:database_user).and_return({})
result = subject.db_create_with_user('compute', 'user', 'pass')
expect(result['host']).to eq('127.0.0.1')
expect(result['port']).to eq('3306')
end
it 'creates database' do
skip 'TODO: test this LWRP'
end
it 'creates database user' do
skip 'TODO: test this LWRP'
end
it 'grants privs to database user' do
skip 'TODO: test this LWRP'
end
end
end
end