Fix incomplete unit tests for swift::objectexpirer

This fixes some of the logics which do not actually enable unit tests,
to keep appropriate test coverage.

Change-Id: I02d7f2a21d0b2a3c09f622caf11041a6dd9d0f83
This commit is contained in:
Takashi Kajinami 2023-12-04 15:35:23 +09:00
parent 4ae639589e
commit 9c10d867f3
1 changed files with 36 additions and 52 deletions

View File

@ -2,26 +2,6 @@ require 'spec_helper'
describe 'swift::objectexpirer' do describe 'swift::objectexpirer' do
let :default_params do
{ :manage_service => true,
:enabled => true,
:package_ensure => 'present',
:pipeline => ['catch_errors', 'proxy-logging', 'cache', 'proxy-server'],
:concurrency => '<SERVICE DEFAULT>',
:expiring_objects_account_name => '<SERVICE DEFAULT>',
:interval => '<SERVICE DEFAULT>',
:process => '<SERVICE DEFAULT>',
:processes => '<SERVICE DEFAULT>',
:reclaim_age => '<SERVICE DEFAULT>',
:recon_cache_path => '<SERVICE DEFAULT>',
:report_interval => '<SERVICE DEFAULT>',
:log_facility => 'LOG_LOCAL2',
:log_level => 'INFO',
:memcache_servers => ['127.0.0.1:11211'],
:cache_tls_enabled => false,
}
end
let :params do let :params do
{} {}
end end
@ -30,43 +10,43 @@ describe 'swift::objectexpirer' do
'class { "memcached": max_memory => 1 }' 'class { "memcached": max_memory => 1 }'
end end
shared_examples 'swift::object::expirer' do shared_examples 'swift::objectexpirer' do
let (:p) { default_params.merge!(params) }
context 'with defaults' do context 'with defaults' do
it 'configures object-expirer.conf' do it 'configures object-expirer.conf' do
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'pipeline:main/pipeline').with_value(p[:pipeline].join(' ')) 'pipeline:main/pipeline').with_value('catch_errors proxy-logging cache proxy-server')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/concurrency').with_value(p[:concurrency]) 'object-expirer/concurrency').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/expiring_objects_account_name').with_value(p[:expiring_objects_account_name]) 'object-expirer/expiring_objects_account_name').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/interval').with_value(p[:interval]) 'object-expirer/interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/process').with_value(p[:process]) 'object-expirer/process').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/processes').with_value(p[:processes]) 'object-expirer/processes').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/reclaim_age').with_value(p[:reclaim_age]) 'object-expirer/reclaim_age').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/recon_cache_path').with_value(p[:recon_cache_path]) 'object-expirer/recon_cache_path').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/report_interval').with_value(p[:report_interval]) 'object-expirer/report_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/log_level').with_value(p[:log_level]) 'object-expirer/log_level').with_value('INFO')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'object-expirer/log_facility').with_value(p[:log_facility]) 'object-expirer/log_facility').with_value('LOG_LOCAL2')
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'filter:cache/memcache_servers').with_value(p[:memcache_servers]) 'filter:cache/memcache_servers').with_value('127.0.0.1:11211')
is_expected.to contain_swift_object_expirer_config(
'filter:cache/tls_enabled').with_value(false)
end end
it 'configures object-expirer service' do it 'configures object-expirer service' do
is_expected.to contain_service('swift-object-expirer').with( is_expected.to contain_service('swift-object-expirer').with(
:ensure => (p[:manage_service] && p[:enabled]) ? 'running' : 'stopped', :ensure => 'running',
:name => platform_params[:service_name], :name => platform_params[:service_name],
:provider => platform_params[:service_provider], :provider => platform_params[:service_provider],
:enable => p[:enabled] :enable => true,
) )
end end
end end
@ -79,6 +59,14 @@ describe 'swift::objectexpirer' do
:concurrency => '3', :concurrency => '3',
) )
end end
it 'configures object-expirer.conf' do
is_expected.to contain_swift_object_expirer_config(
'object-expirer/concurrency').with_value('3')
is_expected.to contain_swift_object_expirer_config(
'object-expirer/interval').with_value('600')
is_expected.to contain_swift_object_expirer_config(
'object-expirer/reclaim_age').with_value('10000')
end
end end
context 'when cache is not included in pipeline' do context 'when cache is not included in pipeline' do
@ -91,16 +79,14 @@ describe 'swift::objectexpirer' do
it 'should not configure memcache servers' do it 'should not configure memcache servers' do
is_expected.to contain_swift_object_expirer_config( is_expected.to contain_swift_object_expirer_config(
'filter:cache/memcache_servers').with_ensure('absent') 'filter:cache/memcache_servers').with_ensure('absent')
end is_expected.to contain_swift_object_expirer_config(
end 'filter:cache/tls_enabled').with_ensure('absent')
is_expected.to contain_swift_object_expirer_config(
context 'when using swiftinit service provider' do 'filter:cache/tls_cafile').with_ensure('absent')
before do is_expected.to contain_swift_object_expirer_config(
params.merge!({ :service_provider => 'swiftinit' }) 'filter:cache/tls_certfile').with_ensure('absent')
end is_expected.to contain_swift_object_expirer_config(
'filter:cache/tls_keyfile').with_ensure('absent')
before do
platform_params.merge!({ :service_provider => 'swiftinit' })
end end
end end
end end
@ -116,15 +102,13 @@ describe 'swift::objectexpirer' do
let(:platform_params) do let(:platform_params) do
case facts[:os]['family'] case facts[:os]['family']
when 'Debian' when 'Debian'
{ :service_name => 'swift-object-expirer', { :service_name => 'swift-object-expirer' }
:service_provider => nil }
when 'RedHat' when 'RedHat'
{ :service_name => 'openstack-swift-object-expirer', { :service_name => 'openstack-swift-object-expirer' }
:service_provider => nil }
end end
end end
it_configures 'swift::object::expirer' it_configures 'swift::objectexpirer'
end end
end end