Merge "Convert to rspec-puppet-facts"

This commit is contained in:
Zuul
2018-11-27 06:50:29 +00:00
committed by Gerrit Code Review
2 changed files with 82 additions and 86 deletions

View File

@@ -1,59 +1,70 @@
require 'spec_helper'
describe 'rally::db::mysql' do
let :pre_condition do
[
'include mysql::server'
]
end
let :facts do
{ :osfamily => 'Debian' }
"include mysql::server"
end
let :params do
{
'password' => 'fooboozoo_default_password',
:password => 'fooboozoo_default_password',
}
end
describe 'with only required params' do
it { is_expected.to contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
)}
shared_examples 'rally::db::mysql' do
context 'with only required params' do
it { should contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
)}
end
context 'overriding allowed_hosts param to array' do
before do
params.merge!( :allowed_hosts => ['127.0.0.1','%'] )
end
it { should contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:allowed_hosts => ['127.0.0.1','%']
)}
end
context 'overriding allowed_hosts param to string' do
before do
params.merge!( :allowed_hosts => '192.168.1.1' )
end
it { should contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:allowed_hosts => '192.168.1.1'
)}
end
end
describe "overriding allowed_hosts param to array" do
before { params.merge!( :allowed_hosts => ['127.0.0.1','%'] ) }
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it { is_expected.to contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:allowed_hosts => ['127.0.0.1','%']
)}
it_behaves_like 'rally::db::mysql'
end
end
describe "overriding allowed_hosts param to string" do
before { params.merge!( :allowed_hosts => '192.168.1.1' ) }
it { is_expected.to contain_openstacklib__db__mysql('rally').with(
:user => 'rally',
:password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
:dbname => 'rally',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:allowed_hosts => '192.168.1.1'
)}
end
end

View File

@@ -1,7 +1,6 @@
require 'spec_helper'
describe 'rally::db' do
shared_examples 'rally::db' do
context 'with default parameters' do
it { is_expected.to contain_oslo__db('rally_config').with(
@@ -16,21 +15,19 @@ describe 'rally::db' do
:pool_timeout => '<SERVICE DEFAULT>',
)}
it 'should create sqlite rally directory' do
is_expected.to contain_file('/var/lib/rally').with(
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0755',
:path => '/var/lib/rally',
)
end
it { is_expected.to contain_file('/var/lib/rally').with(
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0755',
:path => '/var/lib/rally',
)}
end
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://rally:rally@localhost/rally',
{
:database_connection => 'mysql://rally:rally@localhost/rally',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_retries => '11',
@@ -53,52 +50,40 @@ describe 'rally::db' do
:max_overflow => '21',
:pool_timeout => '21',
)}
it 'should not create sqlite rally directory' do
is_expected.to_not contain_file('create_sqlite_directory')
end
it { is_expected.to_not contain_file('create_sqlite_directory') }
end
context 'with postgresql backend' do
let :params do
{ :database_connection => 'postgresql://rally:rally@localhost/rally', }
end
it 'install the proper backend package' do
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
{
:database_connection => 'postgresql://rally:rally@localhost/rally'
}
end
it { is_expected.to contain_package('python-psycopg2').with_ensure('present') }
end
context 'with incorrect database_connection string' do
let :params do
{ :database_connection => 'foodb://rally:rally@localhost/rally', }
{
:database_connection => 'foodb://rally:rally@localhost/rally'
}
end
it_raises 'a Puppet::Error', /validate_re/
it { should raise_error(Puppet::Error, /validate_re/) }
end
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => 'jessie',
})
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_behaves_like 'rally::db'
end
it_configures 'rally::db'
end
context 'on Redhat platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
})
end
it_configures 'rally::db'
end
end