Commit e81564f0 authored by Mickaël Canévet's avatar Mickaël Canévet
Browse files

Manage unit tests with rspec-puppet-facts

parent 745509f3
...@@ -48,7 +48,8 @@ ...@@ -48,7 +48,8 @@
"operatingsystem": "RedHat", "operatingsystem": "RedHat",
"operatingsystemrelease": [ "operatingsystemrelease": [
"5", "5",
"6" "6",
"7"
] ]
} }
], ],
......
require 'spec_helper' require 'spec_helper'
describe 'postfix::augeas' do describe 'postfix::augeas' do
let (:facts) { {
:augeasversion => '1.2.0',
:lsbdistcodename => 'wheezy',
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:rubyversion => '1.9.3',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
"include ::augeas" "include ::augeas"
end end
it { is_expected.to contain_augeas__lens('postfix_transport').with( on_supported_os.each do |os, facts|
:ensure => 'present', context "on #{os}" do
:lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug', let(:facts) do
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug', facts.merge({
:stock_since => '1.0.0' :augeasversion => '1.2.0',
) } })
it { is_expected.to contain_augeas__lens('postfix_virtual').with( end
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug', it { is_expected.to compile.with_all_deps }
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
:stock_since => '1.0.0' it { is_expected.to contain_augeas__lens('postfix_transport').with({
) } :ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug',
:stock_since => '1.0.0',
} ) }
it { is_expected.to contain_augeas__lens('postfix_virtual').with({
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
:stock_since => '1.0.0',
}) }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::mailman' do describe 'postfix::mailman' do
let :pre_condition do
"include ::postfix"
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.to compile.with_all_deps }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::mta' do describe 'postfix::mta' do
let (:facts) { {
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
"class { 'postfix': "class { 'postfix':
mydestination => 'bar', mydestination => 'bar',
...@@ -14,7 +9,16 @@ describe 'postfix::mta' do ...@@ -14,7 +9,16 @@ describe 'postfix::mta' do
}" }"
end end
it { is_expected.to contain_postfix__config('mydestination').with_value('bar') } on_supported_os.each do |os, facts|
it { is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.1/8, [::1]/128 ![::2]/128') } context "on #{os}" do
it { is_expected.to contain_postfix__config('relayhost').with_value('foo') } let(:facts) do
facts
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_postfix__config('mydestination').with_value('bar') }
it { is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.1/8, [::1]/128 ![::2]/128') }
it { is_expected.to contain_postfix__config('relayhost').with_value('foo') }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::satellite' do describe 'postfix::satellite' do
let (:node) { 'foo.example.com' }
let (:facts) { {
:augeasversion => '1.2.0',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:rubyversion => '1.9.3',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
" class { 'augeas': } " class { 'augeas': }
class { 'postfix': class { 'postfix':
...@@ -17,9 +9,21 @@ describe 'postfix::satellite' do ...@@ -17,9 +9,21 @@ describe 'postfix::satellite' do
mynetworks => 'baz', mynetworks => 'baz',
}" }"
end end
it { is_expected.to contain_class('postfix::mta') }
it { is_expected.to contain_postfix__virtual('@foo.example.com').with( on_supported_os.each do |os, facts|
:ensure => 'present', context "on #{os}" do
:destination => 'root' let(:facts) do
) } facts.merge({
:augeasversion => '1.2.0',
})
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('postfix::mta') }
it { is_expected.to contain_postfix__virtual('@foo.example.com').with(
:ensure => 'present',
:destination => 'root'
) }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix' do describe 'postfix' do
context 'when using defaults' do
context 'when on Debian' do
let (:facts) { {
:lsbdistcodename => 'wheezy',
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:fqdn => 'fqdn.example.com',
:path => '/foo/bar',
} }
it { is_expected.to contain_package('postfix') } on_supported_os.each do |os, facts|
it { is_expected.to contain_package('mailx') } context "on #{os}" do
let(:facts) do
it { is_expected.to contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") } facts.merge({
it { is_expected.to contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") } :augeasversion => '1.2.0',
it { is_expected.to contain_exec('newaliases').with_refreshonly('true') } })
it { is_expected.to contain_file('/etc/postfix/master.cf').without('seltype') } end
it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') }
it { is_expected.to contain_postfix__config('myorigin').with_value('fqdn.example.com') }
it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
it { is_expected.to contain_postfix__config('inet_interfaces').with_value('all') }
it { is_expected.to contain_mailalias('root').with_recipient('nobody') }
it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/etc/init.d/postfix reload'
) }
end
context 'when on RedHat' do
let (:facts) { {
:fqdn => 'fqdn.example.com',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '7',
:osfamily => 'RedHat',
:path => '/foo/bar',
} }
it { is_expected.to contain_package('postfix') }
it { is_expected.to contain_package('mailx') }
it { is_expected.to contain_file('/etc/mailname').with_seltype('postfix_etc_t').with_content("fqdn.example.com\n") } context 'when using defaults' do
it { is_expected.to contain_file('/etc/aliases').with_seltype('postfix_etc_t').with_content("# file managed by puppet\n") } it { is_expected.to contain_package('postfix') }
it { is_expected.to contain_exec('newaliases').with_refreshonly('true') } it { is_expected.to contain_package('mailx') }
it { is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t') } it { is_expected.to contain_exec('newaliases').with_refreshonly('true') }
it { is_expected.to contain_file('/etc/postfix/main.cf').with_seltype('postfix_etc_t') } it { is_expected.to contain_postfix__config('myorigin').with_value('foo.example.com') }
it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
it { is_expected.to contain_postfix__config('inet_interfaces').with_value('all') }
it { is_expected.to contain_mailalias('root').with_recipient('nobody') }
it { is_expected.to contain_postfix__config('myorigin').with_value('fqdn.example.com') } case facts[:osfamily]
it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') } when 'Debian'
it { is_expected.to contain_postfix__config('inet_interfaces').with_value('all') } it { is_expected.to contain_file('/etc/mailname').without('seltype').with_content("foo.example.com\n") }
it { is_expected.to contain_postfix__config('sendmail_path') } it { is_expected.to contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
it { is_expected.to contain_postfix__config('newaliases_path') } it { is_expected.to contain_file('/etc/postfix/master.cf').without('seltype') }
it { is_expected.to contain_postfix__config('mailq_path') } it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') }
it { is_expected.to contain_mailalias('root').with_recipient('nobody') } it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/etc/init.d/postfix reload'
) }
else
it { is_expected.to contain_file('/etc/mailname').with_seltype('postfix_etc_t').with_content("foo.example.com\n") }
it { is_expected.to contain_file('/etc/aliases').with_seltype('postfix_etc_t').with_content("# file managed by puppet\n") }
it { is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t') }
it { is_expected.to contain_file('/etc/postfix/main.cf').with_seltype('postfix_etc_t') }
it { it { is_expected.to contain_postfix__config('sendmail_path') }
is_expected.to contain_service('postfix').with( it { is_expected.to contain_postfix__config('newaliases_path') }
:ensure => 'running', it { is_expected.to contain_postfix__config('mailq_path') }
:enable => 'true',
:hasstatus => 'true',
:restart => '/bin/systemctl reload postfix'
) }
end
end
context 'when setting parameters' do case facts[:operatingsystemmajrelease]
context 'when on Debian' do when '7'
context "when setting smtp_listen to 'all'" do it {
let (:facts) { { is_expected.to contain_service('postfix').with(
:lsbdistcodename => 'wheezy', :ensure => 'running',
:operatingsystem => 'Debian', :enable => 'true',
:osfamily => 'Debian', :hasstatus => 'true',
:fqdn => 'fqdn.example.com', :restart => '/bin/systemctl reload postfix'
:path => '/foo/bar', ) }
} } else
it {
is_expected.to contain_service('postfix').with(
:ensure => 'running',
:enable => 'true',
:hasstatus => 'true',
:restart => '/etc/init.d/postfix reload'
) }
end
end
end
let (:params) { { context 'when setting parameters' do
:smtp_listen => 'all', case facts[:osfamily]
:root_mail_recipient => 'foo', when 'Debian'
:use_amavisd => true, context "when setting smtp_listen to 'all'" do
:use_dovecot_lda => true, let (:params) { {
:use_schleuder => true, :smtp_listen => 'all',
:use_sympa => true, :root_mail_recipient => 'foo',
:mail_user => 'bar', :use_amavisd => true,
:myorigin => 'localhost', :use_dovecot_lda => true,
:inet_interfaces => 'localhost2', :use_schleuder => true,
:master_smtp => "smtp inet n - - - - smtpd :use_sympa => true,
:mail_user => 'bar',
:myorigin => 'localhost',
:inet_interfaces => 'localhost2',
:master_smtp => "smtp inet n - - - - smtpd
-o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject", -o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject",
:master_smtps => 'smtps inet n - - - - smtpd', :master_smtps => 'smtps inet n - - - - smtpd',
:master_submission => 'submission inet n - - - - smtpd', :master_submission => 'submission inet n - - - - smtpd',
} } } }
it { is_expected.to contain_package('postfix') } it { is_expected.to contain_package('postfix') }
it { is_expected.to contain_package('mailx') } it { is_expected.to contain_package('mailx') }
it { is_expected.to contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") } it { is_expected.to contain_file('/etc/mailname').without('seltype').with_content("foo.example.com\n") }
it { is_expected.to contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") } it { is_expected.to contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
it { is_expected.to contain_exec('newaliases').with_refreshonly('true') } it { is_expected.to contain_exec('newaliases').with_refreshonly('true') }
it { it {
is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content( is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(
/smtp inet n - - - - smtpd/ /smtp inet n - - - - smtpd/
).with_content( ).with_content(
/amavis unix/ /amavis unix/
).with_content( ).with_content(
/dovecot.*\n.* user=bar:bar / /dovecot.*\n.* user=bar:bar /
).with_content( ).with_content(
/schleuder/ /schleuder/
).with_content( ).with_content(
/sympa/ /sympa/
).with_content( ).with_content(
/user=bar/ /user=bar/
).with_content( ).with_content(
/^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/
).with_content( ).with_content(
/^smtps inet n/ /^smtps inet n/
).with_content( ).with_content(
/^submission inet n/ /^submission inet n/
) )
} }
it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') } it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') }
it { is_expected.to contain_postfix__config('myorigin').with_value('localhost') } it { is_expected.to contain_postfix__config('myorigin').with_value('localhost') }
it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') } it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
it { is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') } it { is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') }
it { is_expected.to contain_mailalias('root').with_recipient('foo') } it { is_expected.to contain_mailalias('root').with_recipient('foo') }
it { it {
is_expected.to contain_service('postfix').with( is_expected.to contain_service('postfix').with(
:ensure => 'running', :ensure => 'running',
:enable => 'true', :enable => 'true',
:hasstatus => 'true', :hasstatus => 'true',
:restart => '/etc/init.d/postfix reload' :restart => '/etc/init.d/postfix reload'
) } ) }
end end
end else
context 'when on RedHat' do context 'when specifying inet_interfaces' do
let (:facts) { { let (:params) { {
:augeasversion => '1.2.0', :inet_interfaces => 'localhost2'
:lsbdistcodename => 'wheezy', } }
:operatingsystem => 'Debian', it 'should create a postfix::config defined type with inet_interfaces specified properly' do
:osfamily => 'Debian', is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2')
:rubyversion => '1.9.7', end
:fqdn => 'fqdn.example.com', end
:path => '/foo/bar', context 'when enabling ldap' do
} } it 'should do stuff' do
context 'when specifying inet_interfaces' do skip 'need to write this still'
let (:params) { { end
:inet_interfaces => 'localhost2' end
} } context 'when a custom mail_user is specified' do
it 'should create a postfix::config defined type with inet_interfaces specified properly' do let (:params) { {
is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') :mail_user => 'bar'
end } }
end it 'should adjust the content of /etc/postfix/master.cf specifying the user' do
context 'when enabling ldap' do is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t').with_content(/user=bar/)
it 'should do stuff' do end
skip 'need to write this still' end
end context 'when mailman is true' do
end let (:params) { {
context 'when a custom mail_user is specified' do :mailman => true
let (:params) { { } }
:mail_user => 'bar' it 'should do stuff' do
} } skip 'need to write this still'
it 'should adjust the content of /etc/postfix/master.cf specifying the user' do end
is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(/user=bar/) end
end context 'when specifying a custom mastercf_source' do
end let (:params) { {
context 'when mailman is true' do :mastercf_source => 'testy'
let (:params) { { } }
:mailman => true it 'should do stuff' do
} } skip 'need to write this still'
it 'should do stuff' do end
skip 'need to write this still' end
end context 'when specifying a custom master_smtp' do
end let (:params) { {
context 'when specifying a custom mastercf_source' do :master_smtp => "smtp inet n - - - - smtpd
let (:params) { {
:mastercf_source => 'testy'
} }
it 'should do stuff' do
skip 'need to write this still'
end
end
context 'when specifying a custom master_smtp' do
let (:params) { {
:master_smtp => "smtp inet n - - - - smtpd
-o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject", -o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject",
} } } }
it 'should update master.cf with the specified flags to smtp' do it 'should update master.cf with the specified flags to smtp' do
is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content( is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t').with_content(
/smtp inet n - - - - smtpd/).with_content( /smtp inet n - - - - smtpd/).with_content(
/^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/
) )
end end
end
context 'when specifying a custom master_smtps' do
let (:params) { {
:master_smtps => 'smtps inet n - - - - smtpd'
} }
it 'should update master.cf with the specified flags to smtps' do
is_expected.to contain_file('/etc/postfix/master.cf').with_content(/^smtps inet n/)
end
end
context 'when mta is enabled' do
let (:params) { { :mta => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
it 'should configure postfix as a minimal MTA, delivering mail to the mydestination param' do
is_expected.to contain_postfix__config('mydestination').with_value('1.2.3.4')
is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128')
is_expected.to contain_postfix__config('relayhost').with_value('2.3.4.5')
is_expected.to contain_postfix__config('virtual_alias_maps').with_value('hash:/etc/postfix/virtual')
is_expected.to contain_postfix__config('transport_maps').with_value('hash:/etc/postfix/transport')
end
it { is_expected.to contain_class('postfix::mta') }
context 'and satellite is also enabled' do
let (:params) { { :mta => true, :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
it 'should fail' do
expect { should compile }.to raise_error(/Please disable one/)
end end
end context 'when specifying a custom master_smtps' do
end let (:params) { {
context 'when specifying mydesitination' do :master_smtps => 'smtps inet n - - - - smtpd'
it 'should do stuff' do } }
skip 'need to write this still' it 'should update master.cf with the specified flags to smtps' do
end is_expected.to contain_file('/etc/postfix/master.cf').with_content(/^smtps inet n/)
end end
context 'when specifying mynetworks' do end
it 'should do stuff' do context 'when mta is enabled' do
skip 'need to write this still' let (:params) { { :mta => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
end it 'should configure postfix as a minimal MTA, delivering mail to the mydestination param' do
end is_expected.to contain_postfix__config('mydestination').with_value('1.2.3.4')
context 'when specifying myorigin' do is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128')
let (:params) { { :myorigin => 'localhost'} } is_expected.to contain_postfix__config('relayhost').with_value('2.3.4.5')
it 'should create a postfix::config defined type with myorigin specified properly' do is_expected.to contain_postfix__config('virtual_alias_maps').with_value('hash:/etc/postfix/virtual')
is_expected.to contain_postfix__config('myorigin').with_value('localhost') is_expected.to contain_postfix__config('transport_maps').with_value('hash:/etc/postfix/transport')
end end
end it { is_expected.to contain_class('postfix::mta') }
context 'when specifying relayhost' do context 'and satellite is also enabled' do
it 'should do stuff' do let (:params) { { :mta => true, :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
skip 'need to write this still'