diff --git a/metadata.json b/metadata.json index 5c0e7bb9bcf030cd6c9069a8b5969a90bb0b37b9..c50c05d297bbece74a4d70a1db48dd0329c7d89c 100644 --- a/metadata.json +++ b/metadata.json @@ -48,7 +48,8 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", - "6" + "6", + "7" ] } ], diff --git a/spec/classes/postfix_augeas_spec.rb b/spec/classes/postfix_augeas_spec.rb index ff068e9b287f58cadf6674cdea585adeed505e28..4ea74766e0085ef6e6ec4ce0f2efa00481d1c6b4 100644 --- a/spec/classes/postfix_augeas_spec.rb +++ b/spec/classes/postfix_augeas_spec.rb @@ -1,28 +1,33 @@ require 'spec_helper' 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 "include ::augeas" end - 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' - ) } + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :augeasversion => '1.2.0', + }) + end + + it { is_expected.to compile.with_all_deps } + + 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 diff --git a/spec/classes/postfix_mailman_spec.rb b/spec/classes/postfix_mailman_spec.rb index 15217b46cd87fb8e03ec9257a68c374222a3b6ad..86623d33266b88991f244680fb032928b21c6221 100644 --- a/spec/classes/postfix_mailman_spec.rb +++ b/spec/classes/postfix_mailman_spec.rb @@ -1,4 +1,18 @@ require 'spec_helper' 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 diff --git a/spec/classes/postfix_mta_spec.rb b/spec/classes/postfix_mta_spec.rb index e36911b62570cf00f47758ac2271dc8dea03e6d8..c6be6c75d32ff9a95f2bbfa4b9ccfb86dcc8b650 100644 --- a/spec/classes/postfix_mta_spec.rb +++ b/spec/classes/postfix_mta_spec.rb @@ -1,11 +1,6 @@ require 'spec_helper' describe 'postfix::mta' do - let (:facts) { { - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :path => '/foo/bar', - } } let :pre_condition do "class { 'postfix': mydestination => 'bar', @@ -14,7 +9,16 @@ describe 'postfix::mta' do }" end - 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') } + on_supported_os.each do |os, facts| + context "on #{os}" do + 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 diff --git a/spec/classes/postfix_satellite_spec.rb b/spec/classes/postfix_satellite_spec.rb index a3cf4d53ff8d5a6de61a81500ba4bb68817a1595..ac9489ec63057fc588f2fd444c4468e93b1c402a 100644 --- a/spec/classes/postfix_satellite_spec.rb +++ b/spec/classes/postfix_satellite_spec.rb @@ -1,14 +1,6 @@ require 'spec_helper' 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 " class { 'augeas': } class { 'postfix': @@ -17,9 +9,21 @@ describe 'postfix::satellite' do mynetworks => 'baz', }" end - it { is_expected.to contain_class('postfix::mta') } - it { is_expected.to contain_postfix__virtual('@foo.example.com').with( - :ensure => 'present', - :destination => 'root' - ) } + + on_supported_os.each do |os, facts| + context "on #{os}" do + 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 diff --git a/spec/classes/postfix_spec.rb b/spec/classes/postfix_spec.rb index 1c388a01152007d0b240a72c4093225b2054338c..5113b89a472029ccff6f518c45c18e3d841a0c9d 100644 --- a/spec/classes/postfix_spec.rb +++ b/spec/classes/postfix_spec.rb @@ -1,306 +1,283 @@ require 'spec_helper' 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') } - 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/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_file('/etc/postfix/master.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('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') } + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :augeasversion => '1.2.0', + }) + end - it { is_expected.to contain_file('/etc/mailname').with_seltype('postfix_etc_t').with_content("fqdn.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_exec('newaliases').with_refreshonly('true') } - 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') } + context 'when using defaults' do + it { is_expected.to contain_package('postfix') } + it { is_expected.to contain_package('mailx') } + it { is_expected.to contain_exec('newaliases').with_refreshonly('true') } + 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') } - 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_postfix__config('sendmail_path') } - it { is_expected.to contain_postfix__config('newaliases_path') } - it { is_expected.to contain_postfix__config('mailq_path') } + case facts[:osfamily] + when 'Debian' + 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/postfix/master.cf').without('seltype') } + 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 { - is_expected.to contain_service('postfix').with( - :ensure => 'running', - :enable => 'true', - :hasstatus => 'true', - :restart => '/bin/systemctl reload postfix' - ) } - end - end + it { is_expected.to contain_postfix__config('sendmail_path') } + it { is_expected.to contain_postfix__config('newaliases_path') } + it { is_expected.to contain_postfix__config('mailq_path') } - context 'when setting parameters' do - context 'when on Debian' do - context "when setting smtp_listen to 'all'" do - let (:facts) { { - :lsbdistcodename => 'wheezy', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :fqdn => 'fqdn.example.com', - :path => '/foo/bar', - } } + case facts[:operatingsystemmajrelease] + when '7' + it { + is_expected.to contain_service('postfix').with( + :ensure => 'running', + :enable => 'true', + :hasstatus => 'true', + :restart => '/bin/systemctl reload postfix' + ) } + 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) { { - :smtp_listen => 'all', - :root_mail_recipient => 'foo', - :use_amavisd => true, - :use_dovecot_lda => true, - :use_schleuder => true, - :use_sympa => true, - :mail_user => 'bar', - :myorigin => 'localhost', - :inet_interfaces => 'localhost2', - :master_smtp => "smtp inet n - - - - smtpd + context 'when setting parameters' do + case facts[:osfamily] + when 'Debian' + context "when setting smtp_listen to 'all'" do + let (:params) { { + :smtp_listen => 'all', + :root_mail_recipient => 'foo', + :use_amavisd => true, + :use_dovecot_lda => true, + :use_schleuder => true, + :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", - :master_smtps => 'smtps inet n - - - - smtpd', - :master_submission => 'submission inet n - - - - smtpd', - } } + :master_smtps => 'smtps inet n - - - - smtpd', + :master_submission => 'submission inet n - - - - smtpd', + } } - it { is_expected.to contain_package('postfix') } - it { is_expected.to contain_package('mailx') } + it { is_expected.to contain_package('postfix') } + 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/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_file('/etc/postfix/master.cf').without('seltype').with_content( - /smtp inet n - - - - smtpd/ - ).with_content( - /amavis unix/ - ).with_content( - /dovecot.*\n.* user=bar:bar / - ).with_content( - /schleuder/ - ).with_content( - /sympa/ - ).with_content( - /user=bar/ - ).with_content( - /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ - ).with_content( - /^smtps inet n/ - ).with_content( - /^submission inet n/ - ) - } - it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') } + 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_exec('newaliases').with_refreshonly('true') } + it { + is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content( + /smtp inet n - - - - smtpd/ + ).with_content( + /amavis unix/ + ).with_content( + /dovecot.*\n.* user=bar:bar / + ).with_content( + /schleuder/ + ).with_content( + /sympa/ + ).with_content( + /user=bar/ + ).with_content( + /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ + ).with_content( + /^smtps inet n/ + ).with_content( + /^submission inet n/ + ) + } + 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('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('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('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 { - is_expected.to contain_service('postfix').with( - :ensure => 'running', - :enable => 'true', - :hasstatus => 'true', - :restart => '/etc/init.d/postfix reload' - ) } - end - end - context 'when on RedHat' do - let (:facts) { { - :augeasversion => '1.2.0', - :lsbdistcodename => 'wheezy', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :rubyversion => '1.9.7', - :fqdn => 'fqdn.example.com', - :path => '/foo/bar', - } } - context 'when specifying inet_interfaces' do - let (:params) { { - :inet_interfaces => 'localhost2' - } } - it 'should create a postfix::config defined type with inet_interfaces specified properly' do - is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') - end - end - context 'when enabling ldap' do - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when a custom mail_user is specified' do - let (:params) { { - :mail_user => 'bar' - } } - it 'should adjust the content of /etc/postfix/master.cf specifying the user' do - is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(/user=bar/) - end - end - context 'when mailman is true' do - let (:params) { { - :mailman => true - } } - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when specifying a custom mastercf_source' do - 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 + it { + is_expected.to contain_service('postfix').with( + :ensure => 'running', + :enable => 'true', + :hasstatus => 'true', + :restart => '/etc/init.d/postfix reload' + ) } + end + else + context 'when specifying inet_interfaces' do + let (:params) { { + :inet_interfaces => 'localhost2' + } } + it 'should create a postfix::config defined type with inet_interfaces specified properly' do + is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') + end + end + context 'when enabling ldap' do + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when a custom mail_user is specified' do + let (:params) { { + :mail_user => 'bar' + } } + it 'should adjust the content of /etc/postfix/master.cf specifying the user' do + is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t').with_content(/user=bar/) + end + end + context 'when mailman is true' do + let (:params) { { + :mailman => true + } } + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when specifying a custom mastercf_source' do + 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", - } } - 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( - /smtp inet n - - - - smtpd/).with_content( - /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ - ) - 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/) + } } + it 'should update master.cf with the specified flags to smtp' do + is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t').with_content( + /smtp inet n - - - - smtpd/).with_content( + /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/ + ) + end end - end - end - context 'when specifying mydesitination' do - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when specifying mynetworks' do - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when specifying myorigin' do - let (:params) { { :myorigin => 'localhost'} } - it 'should create a postfix::config defined type with myorigin specified properly' do - is_expected.to contain_postfix__config('myorigin').with_value('localhost') - end - end - context 'when specifying relayhost' do - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when specifying a root_mail_recipient' do - let (:params) { { :root_mail_recipient => 'foo'} } - it 'should contain a Mailalias resource directing roots mail to the required user' do - is_expected.to contain_mailalias('root').with_recipient('foo') - end - end - context 'when specifying satellite' do - let (:params) { { :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } } - let :pre_condition do - "class { 'augeas': }" - end - it 'should configure all local email to be forwarded to $root_mail_recipient delivered through $relayhost' 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 - context 'and mta 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/) + 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 mydesitination' do + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when specifying mynetworks' do + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when specifying myorigin' do + let (:params) { { :myorigin => 'localhost'} } + it 'should create a postfix::config defined type with myorigin specified properly' do + is_expected.to contain_postfix__config('myorigin').with_value('localhost') + end + end + context 'when specifying relayhost' do + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when specifying a root_mail_recipient' do + let (:params) { { :root_mail_recipient => 'foo'} } + it 'should contain a Mailalias resource directing roots mail to the required user' do + is_expected.to contain_mailalias('root').with_recipient('foo') + end + end + context 'when specifying satellite' do + let (:params) { { :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } } + let :pre_condition do + "class { 'augeas': }" + end + it 'should configure all local email to be forwarded to $root_mail_recipient delivered through $relayhost' 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 + context 'and mta 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 smtp_listen' do + let (:params) { { :smtp_listen => 'all' } } + it 'should do stuff' do + skip 'need to write this still' + end + end + context 'when use_amavisd is true' do + let (:params) { { :use_amavisd => true } } + it 'should update master.cf with the specified flags to amavis' do + is_expected.to contain_file('/etc/postfix/master.cf').with_content(/amavis unix/) + end + end + context 'when use_dovecot_lda is true' do + let (:params) { { :use_dovecot_lda => true } } + it 'should update master.cf with the specified flags to dovecot' do + is_expected.to contain_file('/etc/postfix/master.cf').with_content(/dovecot.*\n.* user=vmail:vmail /) + end + end + context 'when use_schleuder is true' do + let (:params) { { :use_schleuder => true } } + it 'should update master.cf with the specified flags to schleuder' do + is_expected.to contain_file('/etc/postfix/master.cf').with_content(/schleuder/) + end + end + context 'when use_sympa is true' do + let (:params) { { :use_sympa => true } } + it 'should update master.cf to include sympa' do + is_expected.to contain_file('/etc/postfix/master.cf').with_content(/sympa/) + end end - end - end - context 'when specifying smtp_listen' do - let (:params) { { :smtp_listen => 'all' } } - it 'should do stuff' do - skip 'need to write this still' - end - end - context 'when use_amavisd is true' do - let (:params) { { :use_amavisd => true } } - it 'should update master.cf with the specified flags to amavis' do - is_expected.to contain_file('/etc/postfix/master.cf').with_content(/amavis unix/) - end - end - context 'when use_dovecot_lda is true' do - let (:params) { { :use_dovecot_lda => true } } - it 'should update master.cf with the specified flags to dovecot' do - is_expected.to contain_file('/etc/postfix/master.cf').with_content(/dovecot.*\n.* user=vmail:vmail /) - end - end - context 'when use_schleuder is true' do - let (:params) { { :use_schleuder => true } } - it 'should update master.cf with the specified flags to schleuder' do - is_expected.to contain_file('/etc/postfix/master.cf').with_content(/schleuder/) - end - end - context 'when use_sympa is true' do - let (:params) { { :use_sympa => true } } - it 'should update master.cf to include sympa' do - is_expected.to contain_file('/etc/postfix/master.cf').with_content(/sympa/) end end end diff --git a/spec/defines/postfix_config_spec.rb b/spec/defines/postfix_config_spec.rb index 75c8edd519fac61718236cefcd50230847dac693..2fe17840027d45c46d47ab253e6f7ae9f35c3598 100644 --- a/spec/defines/postfix_config_spec.rb +++ b/spec/defines/postfix_config_spec.rb @@ -2,93 +2,98 @@ require 'spec_helper' describe 'postfix::config' do let (:title) { 'foo' } - let (:facts) { { - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - } } + let :pre_condition do "class { 'postfix': }" end - context 'when not passing value' do - it 'should fail' do - expect { - is_expected.to contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /value can not be empty/) - end - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - context 'when passing wrong type for value' do - let (:params) { { - :value => ['bar'], - } } - it 'should fail' do - expect { - is_expected.to contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) - end - end + context 'when not passing value' do + it 'should fail' do + expect { + is_expected.to contain_augeas("set postfix 'foo'") + }.to raise_error(Puppet::Error, /value can not be empty/) + end + end - context 'when passing wrong type for ensure' do - let (:params) { { - :value => 'bar', - :ensure => ['present'], - } } - it 'should fail' do - expect { - is_expected.to contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /\["present"\] is not a string/) - end - end + context 'when passing wrong type for value' do + let (:params) { { + :value => ['bar'], + } } + it 'should fail' do + expect { + is_expected.to contain_augeas("set postfix 'foo'") + }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) + end + end - context 'when passing wrong value for ensure' do - let (:params) { { - :value => 'bar', - :ensure => 'running', - } } - it 'should fail' do - expect { - is_expected.to contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/) - end - end + context 'when passing wrong type for ensure' do + let (:params) { { + :value => 'bar', + :ensure => ['present'], + } } + it 'should fail' do + expect { + is_expected.to contain_augeas("set postfix 'foo'") + }.to raise_error(Puppet::Error, /\["present"\] is not a string/) + end + end - context 'when ensuring presence' do - let (:params) { { - :value => 'bar', - :ensure => 'present', - } } + context 'when passing wrong value for ensure' do + let (:params) { { + :value => 'bar', + :ensure => 'running', + } } + it 'should fail' do + expect { + is_expected.to contain_augeas("set postfix 'foo'") + }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/) + end + end - it { is_expected.to contain_augeas("manage postfix 'foo'").with( - :incl => '/etc/postfix/main.cf', - :lens => 'Postfix_Main.lns', - :changes => "set foo 'bar'" - ) } - end + context 'when ensuring presence' do + let (:params) { { + :value => 'bar', + :ensure => 'present', + } } - context 'when ensuring absence' do - let (:params) { { - :value => 'bar', - :ensure => 'absent', - } } + it { is_expected.to contain_augeas("manage postfix 'foo'").with( + :incl => '/etc/postfix/main.cf', + :lens => 'Postfix_Main.lns', + :changes => "set foo 'bar'" + ) } + end - it { is_expected.to contain_augeas("manage postfix 'foo'").with( - :incl => '/etc/postfix/main.cf', - :lens => 'Postfix_Main.lns', - :changes => "rm foo" - ) } - end + context 'when ensuring absence' do + let (:params) { { + :value => 'bar', + :ensure => 'absent', + } } + + it { is_expected.to contain_augeas("manage postfix 'foo'").with( + :incl => '/etc/postfix/main.cf', + :lens => 'Postfix_Main.lns', + :changes => "rm foo" + ) } + end - context 'when ensuring blank' do - let (:params) { { - :value => 'bar', - :ensure => 'blank', - } } + context 'when ensuring blank' do + let (:params) { { + :value => 'bar', + :ensure => 'blank', + } } - it { is_expected.to contain_augeas("manage postfix 'foo'").with( - :incl => '/etc/postfix/main.cf', - :lens => 'Postfix_Main.lns', - :changes => "clear foo" - ) } + it { is_expected.to contain_augeas("manage postfix 'foo'").with( + :incl => '/etc/postfix/main.cf', + :lens => 'Postfix_Main.lns', + :changes => "clear foo" + ) } + end + end end end diff --git a/spec/defines/postfix_hash_spec.rb b/spec/defines/postfix_hash_spec.rb index f6cf28e58a41a87310871a784b2d849bdc08c006..ef80b0f5f04b873ec3ff99814c621ac7f69c496b 100644 --- a/spec/defines/postfix_hash_spec.rb +++ b/spec/defines/postfix_hash_spec.rb @@ -2,103 +2,107 @@ require 'spec_helper' describe 'postfix::hash' do let (:title) { '/tmp/foo' } - let (:facts) { { - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :path => '/foo/bar', - } } + let :pre_condition do "class { '::postfix': }" end - context 'when passing wrong type for ensure' do - let (:params) { { - :ensure => ['present'], - } } - it 'should fail' do - expect { - is_expected.to contain_file('/tmp/foo') - }.to raise_error(Puppet::Error, /\["present"\] is not a string/) - end - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - context 'when passing wrong value for ensure' do - let (:params) { { - :ensure => 'running', - } } - it 'should fail' do - expect { - is_expected.to contain_file('/tmp/foo') - }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/) - end - end + context 'when passing wrong type for ensure' do + let (:params) { { + :ensure => ['present'], + } } + it 'should fail' do + expect { + is_expected.to contain_file('/tmp/foo') + }.to raise_error(Puppet::Error, /\["present"\] is not a string/) + end + end - context 'when passing wrong value for title' do - let (:title) { 'foo' } - it 'should fail' do - expect { - is_expected.to contain_file('/tmp/foo') - }.to raise_error(Puppet::Error, /"foo" is not an absolute path/) - end - end + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'running', + } } + it 'should fail' do + expect { + is_expected.to contain_file('/tmp/foo') + }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/) + end + end - context 'when passing both source and content' do - let (:params) { { - :source => '/tmp/bar', - :content => 'bar', - } } + context 'when passing wrong value for title' do + let (:title) { 'foo' } + it 'should fail' do + expect { + is_expected.to contain_file('/tmp/foo') + }.to raise_error(Puppet::Error, /"foo" is not an absolute path/) + end + end - it 'should fail' do - expect { - is_expected.to contain_file('/tmp/foo') - }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/) - end - end + context 'when passing both source and content' do + let (:params) { { + :source => '/tmp/bar', + :content => 'bar', + } } - context 'when passing source' do - let (:params) { { - :source => '/tmp/bar', - } } + it 'should fail' do + expect { + is_expected.to contain_file('/tmp/foo') + }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/) + end + end - it { is_expected.to contain_file('/tmp/foo').with( - :ensure => 'present', - :source => '/tmp/bar' - ).without(:content) - } - it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } - it { is_expected.to contain_exec('generate /tmp/foo.db') } - end + context 'when passing source' do + let (:params) { { + :source => '/tmp/bar', + } } - context 'when passing content' do - let (:params) { { - :content => 'bar', - } } + it { is_expected.to contain_file('/tmp/foo').with( + :ensure => 'present', + :source => '/tmp/bar' + ).without(:content) + } + it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } + it { is_expected.to contain_exec('generate /tmp/foo.db') } + end - it { is_expected.to contain_file('/tmp/foo').with( - :ensure => 'present', - :content => 'bar' - ).without(:source) - } - it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } - it { is_expected.to contain_exec('generate /tmp/foo.db') } - end + context 'when passing content' do + let (:params) { { + :content => 'bar', + } } - context 'when not passing source or content' do - it { is_expected.to contain_file('/tmp/foo').with( - :ensure => 'present' - ).without(:source).without(:content) - } - it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } - it { is_expected.to contain_exec('generate /tmp/foo.db') } - end + it { is_expected.to contain_file('/tmp/foo').with( + :ensure => 'present', + :content => 'bar' + ).without(:source) + } + it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } + it { is_expected.to contain_exec('generate /tmp/foo.db') } + end + + context 'when not passing source or content' do + it { is_expected.to contain_file('/tmp/foo').with( + :ensure => 'present' + ).without(:source).without(:content) + } + it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } + it { is_expected.to contain_exec('generate /tmp/foo.db') } + end - context 'when ensuring absence' do - let (:params) { { - :ensure => 'absent', - } } + context 'when ensuring absence' do + let (:params) { { + :ensure => 'absent', + } } - it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') } - it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') } - it { is_expected.to contain_exec('generate /tmp/foo.db') } + it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') } + it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') } + it { is_expected.to contain_exec('generate /tmp/foo.db') } + end + end end end diff --git a/spec/defines/postfix_transport_spec.rb b/spec/defines/postfix_transport_spec.rb index ad497170eaff6abe6341d1870b560bab9440b6d9..05904998293bff290aeb0774bd91786286d36265 100644 --- a/spec/defines/postfix_transport_spec.rb +++ b/spec/defines/postfix_transport_spec.rb @@ -2,139 +2,144 @@ require 'spec_helper' describe 'postfix::transport' do let (:title) { 'foo' } - let (:facts) { { - :augeasversion => '1.2.0', - :osfamily => 'Debian', - :rubyversion => '1.9.3', - :path => '/foo/bar', - } } - let :pre_condition do - "class { 'augeas': }" - end - - context 'when sending wrong type for destination' do - let (:params) { { - :destination => ['bar'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) - end - end - - context 'when sending wrong type for nexthop' do - let (:params) { { - :destination => 'bar', - :nexthop => ['baz'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) - end - end - - context 'when sending wrong type for file' do - let (:params) { { - :destination => 'bar', - :file => ['baz'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) - end - end - context 'when sending wrong value for file' do - let (:params) { { - :destination => 'bar', - :file => 'baz', - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /"baz" is not an absolute path/) - end - end - - context 'when sending wrong type for ensure' do - let (:params) { { - :destination => 'bar', - :ensure => ['baz'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) - end + let :pre_condition do + "class { '::augeas': }" end - context 'when sending wrong value for ensure' do - let (:params) { { - :destination => 'bar', - :ensure => 'running', - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix transport - foo') - }.to raise_error(Puppet::Error, /\$ensure must be either/) + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :augeasversion => '1.2.0', + }) + end + + context 'when sending wrong type for destination' do + let (:params) { { + :destination => ['bar'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) + end + end + + context 'when sending wrong type for nexthop' do + let (:params) { { + :destination => 'bar', + :nexthop => ['baz'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) + end + end + + context 'when sending wrong type for file' do + let (:params) { { + :destination => 'bar', + :file => ['baz'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) + end + end + + context 'when sending wrong value for file' do + let (:params) { { + :destination => 'bar', + :file => 'baz', + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /"baz" is not an absolute path/) + end + end + + context 'when sending wrong type for ensure' do + let (:params) { { + :destination => 'bar', + :ensure => ['baz'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) + end + end + + context 'when sending wrong value for ensure' do + let (:params) { { + :destination => 'bar', + :ensure => 'running', + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix transport - foo') + }.to raise_error(Puppet::Error, /\$ensure must be either/) + end + end + + context 'when using default values' do + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix transport - foo').with( + :incl => '/etc/postfix/transport', + :lens => 'Postfix_Transport.lns', + :changes => [ + "set pattern[. = 'foo'] 'foo'", + "clear pattern[. = 'foo']/transport", + "clear pattern[. = 'foo']/nexthop", + ]) + } + end + + context 'when overriding default values' do + let (:params) { { + :destination => 'bar', + :nexthop => 'baz', + :file => '/tmp/transport', + :ensure => 'present', + } } + + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix transport - foo').with( + :incl => '/tmp/transport', + :lens => 'Postfix_Transport.lns', + :changes => [ + "set pattern[. = 'foo'] 'foo'", + "set pattern[. = 'foo']/transport 'bar'", + "set pattern[. = 'foo']/nexthop 'baz'", + ]) + } + end + + context 'when ensuring absence' do + let (:params) { { + :destination => 'bar', + :ensure => 'absent', + } } + + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix transport - foo').with( + :incl => '/etc/postfix/transport', + :lens => 'Postfix_Transport.lns', + :changes => [ + "rm pattern[. = 'foo']", + ]) + } + end end end - - context 'when using default values' do - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix transport - foo').with( - :incl => '/etc/postfix/transport', - :lens => 'Postfix_Transport.lns', - :changes => [ - "set pattern[. = 'foo'] 'foo'", - "clear pattern[. = 'foo']/transport", - "clear pattern[. = 'foo']/nexthop", - ]) - } - end - - context 'when overriding default values' do - let (:params) { { - :destination => 'bar', - :nexthop => 'baz', - :file => '/tmp/transport', - :ensure => 'present', - } } - - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix transport - foo').with( - :incl => '/tmp/transport', - :lens => 'Postfix_Transport.lns', - :changes => [ - "set pattern[. = 'foo'] 'foo'", - "set pattern[. = 'foo']/transport 'bar'", - "set pattern[. = 'foo']/nexthop 'baz'", - ]) - } - end - - context 'when ensuring absence' do - let (:params) { { - :destination => 'bar', - :ensure => 'absent', - } } - - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix transport - foo').with( - :incl => '/etc/postfix/transport', - :lens => 'Postfix_Transport.lns', - :changes => [ - "rm pattern[. = 'foo']", - ]) - } - end end diff --git a/spec/defines/postfix_virtual_spec.rb b/spec/defines/postfix_virtual_spec.rb index 36a056b2c42a5205ad7bcc3f6ff7abd872172a38..38927652ac040e8307b8aad64ce6e667ab05569d 100644 --- a/spec/defines/postfix_virtual_spec.rb +++ b/spec/defines/postfix_virtual_spec.rb @@ -2,135 +2,140 @@ require 'spec_helper' describe 'postfix::virtual' do let (:title) { 'foo' } - let (:facts) { { - :augeasversion => '1.2.0', - :osfamily => 'Debian', - :rubyversion => '1.9.3', - :path => '/foo/bar', - } } - let :pre_condition do - "class { 'augeas': }" - end - - context 'when not sending destination' do - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /Must pass destination/) - end - end - - context 'when sending wrong type for destination' do - let (:params) { { - :destination => ['bar'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) - end - end - - context 'when sending wrong type for file' do - let (:params) { { - :destination => 'bar', - :file => ['baz'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) - end - end - - context 'when sending wrong value for file' do - let (:params) { { - :destination => 'bar', - :file => 'baz', - } } - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /"baz" is not an absolute path/) - end - end - - context 'when sending wrong type for ensure' do - let (:params) { { - :destination => 'bar', - :ensure => ['baz'], - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) - end + let :pre_condition do + "class { '::augeas': }" end - context 'when sending wrong value for ensure' do - let (:params) { { - :destination => 'bar', - :ensure => 'running', - } } - - it 'should fail' do - expect { - is_expected.to contain_augeas('Postfix virtual - foo') - }.to raise_error(Puppet::Error, /\$ensure must be either/) + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :augeasversion => '1.2.0', + }) + end + + context 'when not sending destination' do + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /Must pass destination/) + end + end + + context 'when sending wrong type for destination' do + let (:params) { { + :destination => ['bar'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /\["bar"\] is not a string/) + end + end + + context 'when sending wrong type for file' do + let (:params) { { + :destination => 'bar', + :file => ['baz'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) + end + end + + context 'when sending wrong value for file' do + let (:params) { { + :destination => 'bar', + :file => 'baz', + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /"baz" is not an absolute path/) + end + end + + context 'when sending wrong type for ensure' do + let (:params) { { + :destination => 'bar', + :ensure => ['baz'], + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /\["baz"\] is not a string/) + end + end + + context 'when sending wrong value for ensure' do + let (:params) { { + :destination => 'bar', + :ensure => 'running', + } } + + it 'should fail' do + expect { + is_expected.to contain_augeas('Postfix virtual - foo') + }.to raise_error(Puppet::Error, /\$ensure must be either/) + end + end + + context 'when using default values' do + let (:params) { { + :destination => 'bar', + } } + + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix virtual - foo').with( + :incl => '/etc/postfix/virtual', + :lens => 'Postfix_Virtual.lns', + :changes => [ + "set pattern[. = 'foo'] 'foo'", + "set pattern[. = 'foo']/destination 'bar'", + ]) + } + end + + context 'when overriding default values' do + let (:params) { { + :destination => 'bar', + :file => '/tmp/virtual', + :ensure => 'present', + } } + + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix virtual - foo').with( + :incl => '/tmp/virtual', + :lens => 'Postfix_Virtual.lns', + :changes => [ + "set pattern[. = 'foo'] 'foo'", + "set pattern[. = 'foo']/destination 'bar'", + ]) + } + end + + context 'when ensuring absence' do + let (:params) { { + :destination => 'bar', + :ensure => 'absent', + } } + + it { is_expected.to contain_class('postfix::augeas') } + it { is_expected.to contain_augeas('Postfix virtual - foo').with( + :incl => '/etc/postfix/virtual', + :lens => 'Postfix_Virtual.lns', + :changes => [ + "rm pattern[. = 'foo']", + ]) + } + end end end - - context 'when using default values' do - let (:params) { { - :destination => 'bar', - } } - - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix virtual - foo').with( - :incl => '/etc/postfix/virtual', - :lens => 'Postfix_Virtual.lns', - :changes => [ - "set pattern[. = 'foo'] 'foo'", - "set pattern[. = 'foo']/destination 'bar'", - ]) - } - end - - context 'when overriding default values' do - let (:params) { { - :destination => 'bar', - :file => '/tmp/virtual', - :ensure => 'present', - } } - - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix virtual - foo').with( - :incl => '/tmp/virtual', - :lens => 'Postfix_Virtual.lns', - :changes => [ - "set pattern[. = 'foo'] 'foo'", - "set pattern[. = 'foo']/destination 'bar'", - ]) - } - end - - context 'when ensuring absence' do - let (:params) { { - :destination => 'bar', - :ensure => 'absent', - } } - - it { is_expected.to contain_class('postfix::augeas') } - it { is_expected.to contain_augeas('Postfix virtual - foo').with( - :incl => '/etc/postfix/virtual', - :lens => 'Postfix_Virtual.lns', - :changes => [ - "rm pattern[. = 'foo']", - ]) - } - end end