diff --git a/.sync.yml b/.sync.yml index ace7fcbc..563ac7c2 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,3 +1,5 @@ --- .travis.yml: forge_password: "XAv4O363tng0KuRnu1ZhhwORy+2CF9UQwdwlFmS+NG9jOaTZZN+PMK8iC7OSIvZN6cfKlYjHRHNuxFBnYlnMrLsM9fVxt4NjjznOgIKQpQDleWk4UitZj5ntyHmUtYtofUd5Bhi/sdYXwGN9pVRCrcfFBmsIRq/dOhXD7Wy5KcQ=" +#README.md: +# include: ['.sync/simple_usage.md', '.sync/classes.md'] diff --git a/.sync/classes.md b/.sync/classes.md new file mode 100644 index 00000000..1764de09 --- /dev/null +++ b/.sync/classes.md @@ -0,0 +1,24 @@ +## Classes + +### postfix + +The top-level class, to install and configure Postfix. + +## Definitions + +### postfix::config + +Add/alter/remove options in Postfix main configuration file (main.cf) + +### postfix::hash + +Creates Postfix hashed "map" files, and build the corresponding db file. + +### postfix::transport + +Manages content in the transport map. + +### postfix::virtual + +Manages content in the virtual map. + diff --git a/.sync/simple_usage.md b/.sync/simple_usage.md new file mode 100644 index 00000000..34f5e887 --- /dev/null +++ b/.sync/simple_usage.md @@ -0,0 +1,22 @@ +This module requires Augeas. + +## Simple usage + + include postfix + + postfix::config { "relay_domains": value => "localhost host.foo.com" } + +## Exec paths + +In order to not have any path problem, you should add the following line in +some globally included .pp file: + + Exec { + path => '/some/relevant/path:/some/other:...', + } + +For example: + + Exec { + path => '/bin:/sbin:/usr/sbin:/usr/bin', + } diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c65aa9..d4a2ffb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 2015-03-24 - Release 1.1.1 + +- Various spec improvements + +## 2015-02-19 - Release 1.1.0 + +- Various specs improvements +- Fix specs for postfix::config with ensure => blank +- Simplify relationships and avoid spaceship operators +- nexthop parameter is not necessary for postfix::canonical + ## 2015-01-07 - Release 1.0.5 - Fix unquoted strings in cases diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..2c179eb4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,8 @@ +# How to contribute + +Please report bugs and feature request using [GitHub issue +tracker](https://github.com/camptocamp/puppet-postfix/issues). + +For pull requests, it is very much appreciated to check your Puppet manifest +with [puppet-lint](https://github.com/rodjek/puppet-lint) to follow the recommended Puppet style guidelines from the +[Puppet Labs style guide](http://docs.puppetlabs.com/guides/style_guide.html). diff --git a/Gemfile b/Gemfile index f1bdbfc8..57fcd086 100644 --- a/Gemfile +++ b/Gemfile @@ -2,23 +2,26 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" group :development, :unit_tests do gem 'rake', :require => false - gem 'rspec-puppet', :require => false, :git => 'https://github.com/camptocamp/rspec-puppet.git', :branch => 'rspec3' + gem 'rspec', '< 3.2', :require => false if RUBY_VERSION =~ /^1.8/ + gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'puppet-lint', '~> 1.0.0', :require => false + gem 'metadata-json-lint', :require => false + gem 'puppet-lint', :require => false gem 'puppet-lint-unquoted_string-check', :require => false gem 'puppet-lint-empty_string-check', :require => false gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false gem 'puppet-lint-variable_contains_upcase', :require => false gem 'puppet-lint-absolute_classname-check', :require => false gem 'puppet-lint-undef_in_function-check', :require => false - gem 'simplecov', :require => false + gem 'puppet-lint-leading_zero-check', :require => false + gem 'puppet-lint-trailing_comma-check', :require => false + gem 'puppet-lint-file_ensure-check', :require => false + gem 'puppet-lint-version_comparison-check', :require => false gem 'rspec-puppet-facts', :require => false - gem 'json', :require => false - gem 'metadata-json-lint', :require => false end group :system_tests do - gem 'beaker', :require => false, :git => 'https://github.com/mcanevet/beaker', :branch => 'openstack' + gem 'beaker', :require => false gem 'beaker-rspec', :require => false gem 'serverspec', :require => false end diff --git a/README.md b/README.md index 3672aaf3..7ac19f93 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ -# Postfix module for Puppet +# Postfix Puppet Module -[![Puppet Forge](http://img.shields.io/puppetforge/v/camptocamp/postfix.svg)](https://forge.puppetlabs.com/camptocamp/postfix) -[![Build Status](https://travis-ci.org/camptocamp/puppet-postfix.png?branch=master)](https://travis-ci.org/camptocamp/puppet-postfix) - -**Manages Postfix configuration.** - -This module is provided by [Camptocamp](http://www.camptocamp.com/) +[![Puppet Forge Version](http://img.shields.io/puppetforge/v/camptocamp/postfix.svg)](https://forge.puppetlabs.com/camptocamp/postfix) +[![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/camptocamp/postfix.svg)](https://forge.puppetlabs.com/camptocamp/postfix) +[![Build Status](https://img.shields.io/travis/camptocamp/puppet-postfix/master.svg)](https://travis-ci.org/camptocamp/puppet-postfix) +[![Gemnasium](https://img.shields.io/gemnasium/camptocamp/puppet-postfix.svg)](https://gemnasium.com/camptocamp/puppet-postfix) +[![By Camptocamp](https://img.shields.io/badge/by-camptocamp-fb7047.svg)](http://www.camptocamp.com) This module requires Augeas. @@ -54,29 +53,4 @@ Manages content in the transport map. Manages content in the virtual map. -## Contributing - -Please report bugs and feature request using [GitHub issue -tracker](https://github.com/camptocamp/puppet-postfix/issues). - -For pull requests, it is very much appreciated to check your Puppet manifest -with [puppet-lint](https://github.com/camptocamp/puppet-postfix/issues) to follow the recommended Puppet style guidelines from the -[Puppet Labs style guide](http://docs.puppetlabs.com/guides/style_guide.html). - -## License - -Copyright (c) 2013 All rights reserved. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . diff --git a/Rakefile b/Rakefile index a81b2c6f..f87e6088 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,11 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.fail_on_warnings -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] +Rake::Task[:lint].clear +PuppetLint::RakeTask.new :lint do |config| + config.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] + config.disable_checks = ['80chars'] + config.fail_on_warnings = true +end PuppetSyntax.exclude_paths = ["spec/fixtures/**/*.pp", "vendor/**/*"] - -desc "Lint metadata.json file" -task :metadata do - sh "metadata-json-lint metadata.json" -end diff --git a/manifests/hash.pp b/manifests/hash.pp index 076f7450..1d5e6300 100644 --- a/manifests/hash.pp +++ b/manifests/hash.pp @@ -31,8 +31,10 @@ include ::postfix::params validate_absolute_path($name) - validate_string($source) - validate_string($content) +# validate_string($source) +# validate_string($content) + if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") } + if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") } validate_string($ensure) validate_re($ensure, ['present', 'absent'], "\$ensure must be either 'present' or 'absent', got '${ensure}'") @@ -66,6 +68,7 @@ exec {"generate ${name}.db": command => "postmap ${name}", + path => $::path, #creates => "${name}.db", # this prevents postmap from being run ! subscribe => File[$name], refreshonly => true, diff --git a/manifests/init.pp b/manifests/init.pp index db2a097a..0af6148b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -82,7 +82,7 @@ $master_submission = undef, # postfix_master_submission $mta = false, $mydestination = '$myorigin', # postfix_mydestination - $mynetworks = '127.0.0.0/8', # postfix_mynetworks + $mynetworks = '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128', # postfix_mynetworks $myorigin = $::fqdn, $relayhost = undef, # postfix_relayhost $root_mail_recipient = 'nobody', # root_mail_recipient diff --git a/manifests/ldap.pp b/manifests/ldap.pp index d6c40be1..679cf1e3 100644 --- a/manifests/ldap.pp +++ b/manifests/ldap.pp @@ -14,8 +14,11 @@ # include postfix::ldap # class postfix::ldap { - - package {'postfix-ldap': } + if $::osfamily == 'Debian' { + package {'postfix-ldap': + before => File['/etc/postfix/ldap-aliases.cf'], + } + } if ! $postfix::ldap_base { fail 'Missing $postfix::ldap_base !' @@ -36,6 +39,5 @@ owner => 'root', group => 'postfix', content => template('postfix/postfix-ldap-aliases.cf.erb'), - require => Package['postfix-ldap'], } } diff --git a/manifests/mta.pp b/manifests/mta.pp index 7df275eb..b96927d1 100644 --- a/manifests/mta.pp +++ b/manifests/mta.pp @@ -35,7 +35,7 @@ 'Wrong value for $relayhost') validate_re($mydestination, '^\S+(?:,\s*\S+)*$', 'Wrong value for $mydestination') - validate_re($mynetworks, '^\S+$', + validate_re($mynetworks, '^(?:\S+?(?:(?:,\s)|(?:\s))?)*$', 'Wrong value for $mynetworks') # If direct is specified then relayhost should be blank diff --git a/manifests/params.pp b/manifests/params.pp index dde5339d..74e55d79 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,6 +7,11 @@ default => undef, } + $restart_cmd = $::operatingsystemmajrelease ? { + '7' => '/bin/systemctl reload postfix', + default => '/etc/init.d/postfix reload', + } + $mailx_package = 'mailx' $master_os_template = "${module_name}/master.cf.redhat.erb" @@ -15,9 +20,11 @@ 'Debian': { $seltype = undef + $restart_cmd = '/etc/init.d/postfix reload' + $mailx_package = $::lsbdistcodename ? { - /sarge|etch|lenny|lucid/ => 'mailx', - default => 'bsd-mailx', + /sarge|etch|lenny/ => 'mailx', + default => 'bsd-mailx', } $master_os_template = "${module_name}/master.cf.debian.erb" @@ -26,6 +33,8 @@ 'Suse': { $seltype = undef + $restart_cmd = '/etc/init.d/postfix reload' + $mailx_package = 'mailx' if $::operatingsystem != 'SLES' { diff --git a/manifests/service.pp b/manifests/service.pp index c3f185da..9d56cd2e 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -3,6 +3,6 @@ ensure => running, enable => true, hasstatus => true, - restart => '/etc/init.d/postfix reload', + restart => $::postfix::params::restart_cmd, } } diff --git a/metadata.json b/metadata.json index 1dcc0576..c50c05d2 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "camptocamp-postfix", - "version": "1.0.5", + "version": "1.1.1", "author": "Camptocamp", "summary": "Camptocamp Postfix Module", "license": "Apache-2.0", @@ -48,7 +48,8 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", - "6" + "6", + "7" ] } ], diff --git a/spec/acceptance/nodesets/centos-7-x86_64-docker.yml b/spec/acceptance/nodesets/centos-7-x86_64-docker.yml index 6eb5641a..599a681f 100644 --- a/spec/acceptance/nodesets/centos-7-x86_64-docker.yml +++ b/spec/acceptance/nodesets/centos-7-x86_64-docker.yml @@ -1,5 +1,5 @@ HOSTS: - centos-7-x86_64: + centos-7-x64: default_apply_opts: strict_variables: platform: el-7-x86_64 diff --git a/spec/acceptance/nodesets/centos-7-x86_64-openstack.yml b/spec/acceptance/nodesets/centos-7-x86_64-openstack.yml index 69d1bfc0..2036c0b8 100644 --- a/spec/acceptance/nodesets/centos-7-x86_64-openstack.yml +++ b/spec/acceptance/nodesets/centos-7-x86_64-openstack.yml @@ -1,10 +1,10 @@ HOSTS: - centos-7-x86_64: + centos-7-x64: default_apply_opts: strict_variables: platform: el-7-x86_64 hypervisor : openstack - flavor: m1.small + flavor: m1.medium image: centos-7-x86_64-genericcloud-20140929_01 user: centos CONFIG: diff --git a/spec/acceptance/nodesets/centos-7-x86_64-vagrant.yml b/spec/acceptance/nodesets/centos-7-x86_64-vagrant.yml index d4794280..fe0f83b8 100644 --- a/spec/acceptance/nodesets/centos-7-x86_64-vagrant.yml +++ b/spec/acceptance/nodesets/centos-7-x86_64-vagrant.yml @@ -1,10 +1,10 @@ HOSTS: - centos-7-x86_64: + centos-7-x64: default_apply_opts: strict_variables: platform: el-7-x86_64 hypervisor : vagrant - box : puppetlabs/centos-6.5-64-nocm + box : puppetlabs/centos-7.0-64-nocm CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/debian-6-x86_64-docker.yml b/spec/acceptance/nodesets/debian-6-x86_64-docker.yml index b6cf1e6d..0296d129 100644 --- a/spec/acceptance/nodesets/debian-6-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-6-x86_64-docker.yml @@ -1,5 +1,5 @@ HOSTS: - debian-6-x86_64: + debian-6-x64: default_apply_opts: strict_variables: platform: debian-6-amd64 diff --git a/spec/acceptance/nodesets/debian-6-x86_64-vagrant.yml b/spec/acceptance/nodesets/debian-6-x86_64-vagrant.yml new file mode 100644 index 00000000..23dae1b0 --- /dev/null +++ b/spec/acceptance/nodesets/debian-6-x86_64-vagrant.yml @@ -0,0 +1,10 @@ +HOSTS: + debian-6-x64: + default_apply_opts: + strict_variables: + platform: debian-6-amd64 + hypervisor : vagrant + box : puppetlabs/debian-6.0.10-64-nocm +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/nodesets/debian-7-x86_64-docker.yml b/spec/acceptance/nodesets/debian-7-x86_64-docker.yml index e7b916bc..ef1c9b22 100644 --- a/spec/acceptance/nodesets/debian-7-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-7-x86_64-docker.yml @@ -1,5 +1,5 @@ HOSTS: - debian-7-x86_64: + debian-7-x64: default_apply_opts: strict_variables: platform: debian-7-amd64 diff --git a/spec/acceptance/nodesets/debian-7-x86_64-openstack.yml b/spec/acceptance/nodesets/debian-7-x86_64-openstack.yml index 0643d036..c44f917e 100644 --- a/spec/acceptance/nodesets/debian-7-x86_64-openstack.yml +++ b/spec/acceptance/nodesets/debian-7-x86_64-openstack.yml @@ -1,10 +1,10 @@ HOSTS: - debian-7-x86_64: + debian-7-x64: default_apply_opts: strict_variables: platform: debian-7-amd64 hypervisor : openstack - flavor: m1.small + flavor: m1.medium image: debian-7-amd64-20141121 user: debian CONFIG: diff --git a/spec/acceptance/nodesets/debian-7-x86_64-vagrant.yml b/spec/acceptance/nodesets/debian-7-x86_64-vagrant.yml index 30f31ad9..86c2165d 100644 --- a/spec/acceptance/nodesets/debian-7-x86_64-vagrant.yml +++ b/spec/acceptance/nodesets/debian-7-x86_64-vagrant.yml @@ -1,11 +1,10 @@ HOSTS: - debian-7-x86_64: + debian-7-x64: default_apply_opts: strict_variables: platform: debian-7-amd64 hypervisor : vagrant - box : debian-73-x64-virtualbox-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box + box : puppetlabs/debian-7.8-64-nocm CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/debian-8-x86_64-docker.yml b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml index ef99efb9..28c3e02f 100644 --- a/spec/acceptance/nodesets/debian-8-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml @@ -1,5 +1,5 @@ HOSTS: - debian-8-x86_64: + debian-8-x64: default_apply_opts: strict_variables: platform: debian-8-amd64 diff --git a/spec/acceptance/nodesets/debian-8-x86_64-openstack.yml b/spec/acceptance/nodesets/debian-8-x86_64-openstack.yml index 1cc9c6d8..f7b2e500 100644 --- a/spec/acceptance/nodesets/debian-8-x86_64-openstack.yml +++ b/spec/acceptance/nodesets/debian-8-x86_64-openstack.yml @@ -1,13 +1,13 @@ HOSTS: - debian-8-x86_64: + debian-8-x64: default_apply_opts: strict_variables: platform: debian-8-amd64 hypervisor : openstack - flavor: m1.small + flavor: m1.medium image: debian-8-amd64-20141121 user: debian CONFIG: type: foss - openstack_network: default log_level: debug + openstack_network: default diff --git a/spec/acceptance/nodesets/debian-8-x86_64-vagrant.yml b/spec/acceptance/nodesets/debian-8-x86_64-vagrant.yml new file mode 100644 index 00000000..38c844be --- /dev/null +++ b/spec/acceptance/nodesets/debian-8-x86_64-vagrant.yml @@ -0,0 +1,10 @@ +HOSTS: + debian-8-x64: + default_apply_opts: + strict_variables: + platform: debian-8-amd64 + hypervisor : vagrant + box : camptocamp/debian-8-amd64 +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml b/spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml new file mode 100644 index 00000000..a3edb70f --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-14.04-x64: + default_apply_opts: + strict_variables: + platform: ubuntu-14.04-amd64 + hypervisor : vagrant + box : puppetlabs/ubuntu-14.04-64-nocm +CONFIG: + type: foss + log_level: debug diff --git a/spec/classes/postfix_augeas_spec.rb b/spec/classes/postfix_augeas_spec.rb index ff068e9b..4ea74766 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 15217b46..86623d33 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 395beaed..c6be6c75 100644 --- a/spec/classes/postfix_mta_spec.rb +++ b/spec/classes/postfix_mta_spec.rb @@ -1,19 +1,24 @@ require 'spec_helper' describe 'postfix::mta' do - let (:facts) { { - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - } } let :pre_condition do "class { 'postfix': mydestination => 'bar', - mynetworks => 'baz', + mynetworks => '127.0.0.1/8, [::1]/128 ![::2]/128', relayhost => 'foo', }" end - it { is_expected.to contain_postfix__config('mydestination').with_value('bar') } - it { is_expected.to contain_postfix__config('mynetworks').with_value('baz') } - 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 a3cf4d53..ac9489ec 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 @@ class { 'postfix': 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 f5e684f4..878ecf51 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 => '/etc/init.d/postfix reload' - ) } - 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') - 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') - 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 75c8edd5..2fe17840 100644 --- a/spec/defines/postfix_config_spec.rb +++ b/spec/defines/postfix_config_spec.rb @@ -2,93 +2,98 @@ 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 6a3220e8..ef80b0f5 100644 --- a/spec/defines/postfix_hash_spec.rb +++ b/spec/defines/postfix_hash_spec.rb @@ -2,102 +2,107 @@ describe 'postfix::hash' do let (:title) { '/tmp/foo' } - let (:facts) { { - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - } } + 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 ad497170..05904998 100644 --- a/spec/defines/postfix_transport_spec.rb +++ b/spec/defines/postfix_transport_spec.rb @@ -2,139 +2,144 @@ 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 36a056b2..38927652 100644 --- a/spec/defines/postfix_virtual_spec.rb +++ b/spec/defines/postfix_virtual_spec.rb @@ -2,135 +2,140 @@ 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