From 90d0a4b625bf3a086bdea20b2d0b89c364d24616 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Sat, 24 Nov 2018 15:46:00 +0100 Subject: [PATCH] Convert to rspec-puppet-facts Change-Id: I56b0591a9978ee0ed5b7338bed82e6a2c9cd2bf6 --- spec/classes/rally_db_mysql_spec.rb | 97 ++++++++++++++++------------- spec/classes/rally_db_spec.rb | 71 +++++++++------------ 2 files changed, 82 insertions(+), 86 deletions(-) diff --git a/spec/classes/rally_db_mysql_spec.rb b/spec/classes/rally_db_mysql_spec.rb index dd31893..fc5d672 100644 --- a/spec/classes/rally_db_mysql_spec.rb +++ b/spec/classes/rally_db_mysql_spec.rb @@ -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 diff --git a/spec/classes/rally_db_spec.rb b/spec/classes/rally_db_spec.rb index ac26f47..61d9850 100644 --- a/spec/classes/rally_db_spec.rb +++ b/spec/classes/rally_db_spec.rb @@ -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 => '', )} - 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