Skip to content

Commit

Permalink
spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trefzer committed Dec 7, 2024
1 parent 5205007 commit a5700f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 103 deletions.
25 changes: 12 additions & 13 deletions spec/defines/config_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@

describe 'postfix::config::service' do
let :default_params do
{ master_cf_file: '/etc/postfix/master.cf' }
{ master_cf_file: '/etc/postfix/master.cf',
order: '55', }
end

shared_examples 'postfix::config::service define' do
context 'it compiles with all dependencies' do
it { is_expected.to compile.with_all_deps }
end
it { is_expected.to compile.with_all_deps }

context 'it includes concat_fragment' do
it {
is_expected.to contain_concat_fragment('master.cf service: ' + title)
.with_target('/etc/postfix/master.cf')
}
end
it {
is_expected.to contain_concat_fragment('master.cf service: ' + title)
.with_target(params[:master_cf_file])
.with_order(params[:order])
}
end

on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'whith defaults' do
let(:title) { 'debian' }
let(:title) { 'smtp' }
let(:params) { default_params }

it_behaves_like 'postfix::config::service define'
end

context 'whith non defaults' do
let(:title) { 'my-repo' }
let(:title) { 'smtp' }

let :params do
default_params.merge(
type: 'fifo',
command: 'fork',
service_names: ['bah'],
service_names: ['smtp'],
order: '100',
master_cf_file: '/local/etc/postfix/master.cf',
)
end

Expand Down
116 changes: 26 additions & 90 deletions spec/defines/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
let(:pre_condition) { 'service {"postfix": }' }
let :default_params do
{ map_dir: '/etc/postfix/maps',
map_name: 'the-title',
type: 'hash',
postmap_command: '/usr/sbin/postmap',
owner: 'root',
group: 'root',
Expand All @@ -16,38 +18,34 @@
it { is_expected.to compile.with_all_deps }
end

context 'it includes map file' do
it {
is_expected.to contain_concat('/etc/postfix/maps/' + title)
.with(owner: 'root',
mode: '0644')
.with_notify('Service[postfix]')
}
end

context 'rebuild map' do
it {
is_expected.to contain_exec('rebuild map ' + title)
.with_command(%r{postmap})
.with_require('Concat[/etc/postfix/maps/' + title + ']')
.with_notify('Service[postfix]')
.with_unless(%r{/etc/postfix/maps/#{title}.db})
}
end
it {
is_expected.to contain_concat(params[:map_dir] + '/' + params[:map_name])
.with(owner: params[:owner],
mode: params[:mode])
.with_notify('Service[postfix]')
}

it {
is_expected.to contain_exec('rebuild map ' + title)
.with_command(params[:postmap_command] + ' ' + params[:type] + ':' + params[:map_dir] + '/' + params[:map_name])
.with_require('Concat[' + params[:map_dir] + '/' + params[:map_name] + ']')
.with_notify('Service[postfix]')
.with_unless("test #{params[:map_dir]}/#{params[:map_name]}.db -nt #{params[:map_dir]}/#{params[:map_name]}")
}
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'whith defaults' do
let(:title) { 'mymap' }
let(:title) { 'the-title' }
let(:params) { default_params }

it_behaves_like 'postfix::map define'
end

context 'whith content defined' do
let(:title) { 'map_with_content' }
let(:title) { 'the-title' }
let :params do
default_params.merge(contents: ['blah1', 'blah2'])
end
Expand All @@ -60,8 +58,8 @@
}
end

context 'whith source defined' do
let(:title) { 'map_with_source' }
context 'with source defined' do
let(:title) { 'the-title' }
let :params do
default_params.merge(source: 'a_source')
end
Expand All @@ -75,102 +73,40 @@
end

context 'whith btree map type' do
let(:title) { 'dbm_map_type' }
let(:title) { 'the-title' }
let :params do
default_params.merge(type: 'btree')
end

it_behaves_like 'postfix::map define'

context 'rebuild btree map' do
it {
is_expected.to contain_exec('rebuild map dbm_map_type')
.with_command('/usr/sbin/postmap btree:/etc/postfix/maps/dbm_map_type')
}
end
end

context 'whith custom map path and name' do
let(:title) { 'custom_map_path_and_name' }
let(:title) { 'the-title' }
let :params do
default_params.merge(
map_dir: '/blah/fasel',
map_name: 'myname',
)
end

context 'it includes map file' do
it {
is_expected.to contain_concat('/blah/fasel/myname')
.with(owner: 'root',
group: 'root',
mode: '0644')
.with_notify('Service[postfix]')
}
end

context 'rebuild map' do
it {
is_expected.to contain_exec('rebuild map custom_map_path_and_name')
.with_command('/usr/sbin/postmap hash:/blah/fasel/myname')
.with_require('Concat[/blah/fasel/myname]')
.with_notify('Service[postfix]')
.with_unless(%r{/blah/fasel/myname.(db|cdb|pag)})
}
end
end

context 'whith custom map path' do
let(:title) { 'custom_map_path' }
let :params do
default_params.merge(
map_dir: '/blah/fasel',
)
end

context 'it includes map file' do
it {
is_expected.to contain_concat('/blah/fasel/custom_map_path')
.with(owner: 'root',
group: 'root',
mode: '0644')
.with_notify('Service[postfix]')
}
end

context 'rebuild map' do
it {
is_expected.to contain_exec('rebuild map custom_map_path')
.with_command('/usr/sbin/postmap hash:/blah/fasel/custom_map_path')
.with_require('Concat[/blah/fasel/custom_map_path]')
.with_notify('Service[postfix]')
.with_unless(%r{/blah/fasel/#{title}.db})
}
end
it_behaves_like 'postfix::map define'
end

context 'whith custom postmap' do
let(:title) { 'custom_postmap' }
let(:title) { 'test-map' }

let :params do
default_params.merge(
postmap_command: 'my_postmap_command',
)
end

context 'rebuild map' do
it {
is_expected.to contain_exec('rebuild map custom_postmap')
.with_command('my_postmap_command hash:/etc/postfix/maps/custom_postmap')
.with_require('Concat[/etc/postfix/maps/custom_postmap]')
.with_notify('Service[postfix]')
.with_unless(%r{/etc/postfix/maps/#{title}.db})
}
end
it_behaves_like 'postfix::map define'
end

context 'whith unknown map type' do
let(:title) { 'unknown_map_type' }
let(:title) { 'the-title' }

let :params do
default_params.merge(
Expand Down

0 comments on commit a5700f0

Please sign in to comment.