diff --git a/.fixtures.yml b/.fixtures.yml index 78f9cf5..69aafa1 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,9 +1,7 @@ --- fixtures: - repositories: - concat: - repo: "https://github.com/puppetlabs/puppetlabs-concat.git" - stdlib: - repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + forge_modules: + concat: puppetlabs/concat + stdlib: puppetlabs/stdlib symlinks: "postfix": "#{source_dir}" diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..9e15c6e 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,9 @@ +--fail-on-warnings --relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/Gemfile b/Gemfile index 8e9f845..f84ea87 100644 --- a/Gemfile +++ b/Gemfile @@ -38,7 +38,8 @@ group :development do end group :development, :release_prep do gem "puppet-strings", '~> 4.0', require: false - gem "puppetlabs_spec_helper", '~> 7.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false end group :system_tests do gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] diff --git a/REFERENCE.md b/REFERENCE.md index e69a2ad..b372705 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -7,14 +7,14 @@ ### Classes * [`postfix`](#postfix): configure postfix, main class -* [`postfix::config::main`](#postfixconfigmain): configures the main.cf file This class is included by postfix::server and postfix::satellite to write the main.cf file -* [`postfix::config::master`](#postfixconfigmaster): configure master.cf -* [`postfix::service`](#postfixservice): create the postfix Service +* [`postfix::config::main`](#postfix--config--main): configures the main.cf file This class is included by postfix::server and postfix::satellite to write the main.cf file +* [`postfix::config::master`](#postfix--config--master): configure master.cf +* [`postfix::service`](#postfix--service): create the postfix Service ### Defined types -* [`postfix::config::service`](#postfixconfigservice): define a service in master.cf file of postfix See master(5) for details -* [`postfix::map`](#postfixmap): this defines a map for postfix you can either use $source or $content parameter or use your own concat::fragment resources to add content to +* [`postfix::config::service`](#postfix--config--service): define a service in master.cf file of postfix See master(5) for details +* [`postfix::map`](#postfix--map): this defines a map for postfix you can either use $source or $content parameter or use your own concat::fragment resources to add content to ## Classes @@ -34,26 +34,26 @@ include postfix The following parameters are available in the `postfix` class: -* [`packages`](#packages) -* [`package_ensure`](#package_ensure) -* [`use_profile`](#use_profile) -* [`parameters`](#parameters) -* [`parameters_profiles`](#parameters_profiles) -* [`services`](#services) -* [`services_profiles`](#services_profiles) -* [`maps`](#maps) -* [`maps_profiles`](#maps_profiles) -* [`map_dir`](#map_dir) -* [`ssl_dir`](#ssl_dir) -* [`owner`](#owner) -* [`group`](#group) -* [`mode`](#mode) -* [`postmap_command`](#postmap_command) -* [`create_resources`](#create_resources) -* [`master_cf_file`](#master_cf_file) -* [`main_cf_file`](#main_cf_file) - -##### `packages` +* [`packages`](#-postfix--packages) +* [`package_ensure`](#-postfix--package_ensure) +* [`use_profile`](#-postfix--use_profile) +* [`parameters`](#-postfix--parameters) +* [`parameters_profiles`](#-postfix--parameters_profiles) +* [`services`](#-postfix--services) +* [`services_profiles`](#-postfix--services_profiles) +* [`maps`](#-postfix--maps) +* [`maps_profiles`](#-postfix--maps_profiles) +* [`map_dir`](#-postfix--map_dir) +* [`ssl_dir`](#-postfix--ssl_dir) +* [`owner`](#-postfix--owner) +* [`group`](#-postfix--group) +* [`mode`](#-postfix--mode) +* [`postmap_command`](#-postfix--postmap_command) +* [`create_resources`](#-postfix--create_resources) +* [`master_cf_file`](#-postfix--master_cf_file) +* [`main_cf_file`](#-postfix--main_cf_file) + +##### `packages` Data type: `Array` @@ -61,15 +61,15 @@ packages to install Default value: `['postfix']` -##### `package_ensure` +##### `package_ensure` Data type: `String` -defaults to 'install' +defaults to 'installed' -Default value: `'present'` +Default value: `'installed'` -##### `use_profile` +##### `use_profile` Data type: `String[1]` @@ -77,7 +77,7 @@ profile for the configuration to use. Default value: `'none'` -##### `parameters` +##### `parameters` Data type: `Hash` @@ -86,7 +86,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `parameters_profiles` +##### `parameters_profiles` Data type: `Hash` @@ -100,7 +100,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `services` +##### `services` Data type: `Hash` @@ -110,7 +110,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `services_profiles` +##### `services_profiles` Data type: `Hash` @@ -124,7 +124,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `maps` +##### `maps` Data type: `Hash` @@ -134,7 +134,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `maps_profiles` +##### `maps_profiles` Data type: `Hash` @@ -148,7 +148,7 @@ Remark: in hiera this parameter is hash merged Default value: `{}` -##### `map_dir` +##### `map_dir` Data type: `String` @@ -156,7 +156,7 @@ directory for maps to create Default value: `'/etc/postfix/maps'` -##### `ssl_dir` +##### `ssl_dir` Data type: `String` @@ -164,7 +164,7 @@ directory for ssl to create Default value: `'/etc/postfix/ssl'` -##### `owner` +##### `owner` Data type: `String` @@ -172,7 +172,7 @@ file and directory owner Default value: `'root'` -##### `group` +##### `group` Data type: `String` @@ -180,7 +180,7 @@ file and directory group Default value: `'root'` -##### `mode` +##### `mode` Data type: `String` @@ -188,7 +188,7 @@ file mode Default value: `'0644'` -##### `postmap_command` +##### `postmap_command` Data type: `String` @@ -196,7 +196,7 @@ the postmap command to use Default value: `'/usr/sbin/postmap'` -##### `create_resources` +##### `create_resources` Data type: `Hash` @@ -204,7 +204,7 @@ generic create_resources (for certificates etc) Default value: `{}` -##### `master_cf_file` +##### `master_cf_file` Data type: `String` @@ -212,7 +212,7 @@ filename and path to master.cf file Default value: `'/etc/postfix/master.cf'` -##### `main_cf_file` +##### `main_cf_file` Data type: `String` @@ -220,7 +220,7 @@ filename and path to main.cf file Default value: `'/etc/postfix/main.cf'` -### `postfix::config::main` +### `postfix::config::main` configures the main.cf file @@ -232,37 +232,37 @@ postfix::satellite to write the main.cf file The following parameters are available in the `postfix::config::main` class: -* [`main_cf_file`](#main_cf_file) -* [`owner`](#owner) -* [`group`](#group) -* [`mode`](#mode) -* [`parameters`](#parameters) +* [`main_cf_file`](#-postfix--config--main--main_cf_file) +* [`owner`](#-postfix--config--main--owner) +* [`group`](#-postfix--config--main--group) +* [`mode`](#-postfix--config--main--mode) +* [`parameters`](#-postfix--config--main--parameters) -##### `main_cf_file` +##### `main_cf_file` Data type: `String` name and path of the main.cf file -##### `owner` +##### `owner` Data type: `String` owner of the main.cf file -##### `group` +##### `group` Data type: `String` group of the main.cf file -##### `mode` +##### `mode` Data type: `String` mode of the main.cf file -##### `parameters` +##### `parameters` Data type: `Hash` @@ -271,7 +271,7 @@ Defaults to {} Default value: `{}` -### `postfix::config::master` +### `postfix::config::master` configure master.cf @@ -279,37 +279,37 @@ configure master.cf The following parameters are available in the `postfix::config::master` class: -* [`master_cf_file`](#master_cf_file) -* [`owner`](#owner) -* [`group`](#group) -* [`mode`](#mode) -* [`services`](#services) +* [`master_cf_file`](#-postfix--config--master--master_cf_file) +* [`owner`](#-postfix--config--master--owner) +* [`group`](#-postfix--config--master--group) +* [`mode`](#-postfix--config--master--mode) +* [`services`](#-postfix--config--master--services) -##### `master_cf_file` +##### `master_cf_file` Data type: `String` name and path for master.cf file -##### `owner` +##### `owner` Data type: `String` owner of master.cf -##### `group` +##### `group` Data type: `String` group of master.cf -##### `mode` +##### `mode` Data type: `String` file mode of master.cf -##### `services` +##### `services` Data type: `Hash` @@ -317,7 +317,7 @@ services to configure (also see README) Default value: `{}` -### `postfix::service` +### `postfix::service` create the postfix Service @@ -325,15 +325,15 @@ create the postfix Service The following parameters are available in the `postfix::service` class: -* [`service_name`](#service_name) -* [`service_ensure`](#service_ensure) -* [`service_enable`](#service_enable) -* [`disabled_services`](#disabled_services) -* [`exec_postfix_enable`](#exec_postfix_enable) -* [`sync_chroot`](#sync_chroot) -* [`ensure_syslog_flag`](#ensure_syslog_flag) +* [`service_name`](#-postfix--service--service_name) +* [`service_ensure`](#-postfix--service--service_ensure) +* [`service_enable`](#-postfix--service--service_enable) +* [`disabled_services`](#-postfix--service--disabled_services) +* [`exec_postfix_enable`](#-postfix--service--exec_postfix_enable) +* [`sync_chroot`](#-postfix--service--sync_chroot) +* [`ensure_syslog_flag`](#-postfix--service--ensure_syslog_flag) -##### `service_name` +##### `service_name` Data type: `String` @@ -341,7 +341,7 @@ The name of the service Default value: `'postfix'` -##### `service_ensure` +##### `service_ensure` Data type: `String` @@ -349,15 +349,15 @@ state of the service. Default value: `'running'` -##### `service_enable` +##### `service_enable` Data type: `Boolean` if service should be enabled -Default value: ``true`` +Default value: `true` -##### `disabled_services` +##### `disabled_services` Data type: `Array` @@ -365,24 +365,24 @@ Array of Services to stop Default value: `[]` -##### `exec_postfix_enable` +##### `exec_postfix_enable` Data type: `Boolean` if set to true, we run postfix-enable -Default value: ``false`` +Default value: `false` -##### `sync_chroot` +##### `sync_chroot` Data type: `Optional[String[1]]` if set to a path, the according chroot is synced. -Default value: ``undef`` +Default value: `undef` -##### `ensure_syslog_flag` +##### `ensure_syslog_flag` Data type: `Boolean` @@ -390,11 +390,11 @@ if set to true, and sync_chroot is choosen, a flag is set to allow logging from chroot this is very OpenBSD specific ! -Default value: ``false`` +Default value: `false` ## Defined types -### `postfix::config::service` +### `postfix::config::service` define a service in master.cf file of postfix @@ -404,21 +404,21 @@ See master(5) for details The following parameters are available in the `postfix::config::service` defined type: -* [`type`](#type) -* [`command`](#command) -* [`args`](#args) -* [`service_names`](#service_names) -* [`priv`](#priv) -* [`unpriv`](#unpriv) -* [`chroot`](#chroot) -* [`wakeup`](#wakeup) -* [`maxproc`](#maxproc) -* [`active`](#active) -* [`comments`](#comments) -* [`order`](#order) -* [`master_cf_file`](#master_cf_file) +* [`type`](#-postfix--config--service--type) +* [`command`](#-postfix--config--service--command) +* [`args`](#-postfix--config--service--args) +* [`service_names`](#-postfix--config--service--service_names) +* [`priv`](#-postfix--config--service--priv) +* [`unpriv`](#-postfix--config--service--unpriv) +* [`chroot`](#-postfix--config--service--chroot) +* [`wakeup`](#-postfix--config--service--wakeup) +* [`maxproc`](#-postfix--config--service--maxproc) +* [`active`](#-postfix--config--service--active) +* [`comments`](#-postfix--config--service--comments) +* [`order`](#-postfix--config--service--order) +* [`master_cf_file`](#-postfix--config--service--master_cf_file) -##### `type` +##### `type` Data type: `String` @@ -428,7 +428,7 @@ defaults to 'unix' Default value: `'unix'` -##### `command` +##### `command` Data type: `String` @@ -437,7 +437,7 @@ defaults to $title Default value: `$title` -##### `args` +##### `args` Data type: `Array` @@ -445,7 +445,7 @@ Array of commands arguments Default value: `[]` -##### `service_names` +##### `service_names` Data type: `Array` @@ -454,7 +454,7 @@ defaults to [$title] Default value: `[$title]` -##### `priv` +##### `priv` Data type: `String` @@ -463,7 +463,7 @@ defaults '-' (use built-in default) Default value: `'-'` -##### `unpriv` +##### `unpriv` Data type: `String` @@ -473,7 +473,7 @@ defaults '-' (use built-in default) Default value: `'-'` -##### `chroot` +##### `chroot` Data type: `String` @@ -483,7 +483,7 @@ defaults '-' (use built-in default) Default value: `'-'` -##### `wakeup` +##### `wakeup` Data type: `String` @@ -492,7 +492,7 @@ defaults 'n' (default for postfix >= 3.0) Default value: `'-'` -##### `maxproc` +##### `maxproc` Data type: `String` @@ -502,16 +502,16 @@ defaults 'n' (default for postfix >= 3.0) Default value: `'-'` -##### `active` +##### `active` Data type: `Boolean` if false, the service will not be activated (commented out) default: true, -Default value: ``true`` +Default value: `true` -##### `comments` +##### `comments` Data type: `Array` @@ -520,7 +520,7 @@ defaults to [] (no comment) Default value: `[]` -##### `order` +##### `order` Data type: `String` @@ -528,13 +528,13 @@ order of the fragment (defaults to '55') Default value: `'55'` -##### `master_cf_file` +##### `master_cf_file` Data type: `String` target -### `postfix::map` +### `postfix::map` this defines a map for postfix @@ -546,29 +546,29 @@ resources to add content to the map. The following parameters are available in the `postfix::map` defined type: -* [`map_dir`](#map_dir) -* [`postmap_command`](#postmap_command) -* [`map_name`](#map_name) -* [`type`](#type) -* [`source`](#source) -* [`contents`](#contents) -* [`owner`](#owner) -* [`group`](#group) -* [`mode`](#mode) +* [`map_dir`](#-postfix--map--map_dir) +* [`postmap_command`](#-postfix--map--postmap_command) +* [`map_name`](#-postfix--map--map_name) +* [`type`](#-postfix--map--type) +* [`source`](#-postfix--map--source) +* [`contents`](#-postfix--map--contents) +* [`owner`](#-postfix--map--owner) +* [`group`](#-postfix--map--group) +* [`mode`](#-postfix--map--mode) -##### `map_dir` +##### `map_dir` Data type: `String` the directory to create the map in -##### `postmap_command` +##### `postmap_command` Data type: `String` postmap command -##### `map_name` +##### `map_name` Data type: `String` @@ -576,7 +576,7 @@ The name of the map defaults to $title Default value: `$title` -##### `type` +##### `type` Data type: `String` @@ -585,16 +585,16 @@ defaults to hash Default value: `'hash'` -##### `source` +##### `source` Data type: `Optional[String[1]]` source of the map defaults to '' -Default value: ``undef`` +Default value: `undef` -##### `contents` +##### `contents` Data type: `Array` @@ -603,19 +603,19 @@ defaults to [] Default value: `[]` -##### `owner` +##### `owner` Data type: `String` owner of the map file -##### `group` +##### `group` Data type: `String` group of the map file -##### `mode` +##### `mode` Data type: `String` diff --git a/Rakefile b/Rakefile index caa4e30..31b5930 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,12 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] diff --git a/manifests/init.pp b/manifests/init.pp index 13c16d3..4581b48 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,7 +7,7 @@ # @param packages # packages to install # @param package_ensure -# defaults to 'install' +# defaults to 'installed' # @param use_profile # profile for the configuration to use. # @param parameters @@ -66,7 +66,7 @@ # class postfix ( Array $packages = ['postfix'], - String $package_ensure = 'present', + String $package_ensure = 'installed', String[1] $use_profile = 'none', Hash $parameters = {}, Hash $parameters_profiles = {}, diff --git a/metadata.json b/metadata.json index 0232daa..d701a4f 100644 --- a/metadata.json +++ b/metadata.json @@ -10,11 +10,11 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 9.0.0" + "version_requirement": ">= 3.2.0 < 10.0.0" }, { "name": "puppetlabs/concat", - "version_requirement": ">= 5.0.0 < 8.0.0" + "version_requirement": ">= 5.0.0 < 10.0.0" } ], "operatingsystem_support": [ @@ -45,7 +45,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=5.0.0 < 8.0.0" + "version_requirement": ">=5.0.0 < 9.0.0" } ], "tags": [ @@ -53,7 +53,7 @@ "mail", "mta" ], - "pdk-version": "3.3.0", - "template-url": "pdk-default#3.3.0", - "template-ref": "tags/3.3.0-0-g5d17ec1" + "pdk-version": "3.4.0", + "template-url": "https://github.com/puppetlabs/pdk-templates#main", + "template-ref": "tags/3.4.0-0-gd3cc13f" } diff --git a/spec/classes/config_main_spec.rb b/spec/classes/config_main_spec.rb index b6fc195..cd2cf21 100644 --- a/spec/classes/config_main_spec.rb +++ b/spec/classes/config_main_spec.rb @@ -6,7 +6,7 @@ { main_cf_file: '/etc/postfix/main.cf', owner: 'root', group: 'root', - mode: '0644' } + mode: '0644', } end shared_examples_for 'postfix::config::main class' do diff --git a/spec/classes/config_master_spec.rb b/spec/classes/config_master_spec.rb index d13551b..5204ce1 100644 --- a/spec/classes/config_master_spec.rb +++ b/spec/classes/config_master_spec.rb @@ -7,7 +7,8 @@ { master_cf_file: '/etc/postfix/master.cf', owner: 'root', group: 'root', - mode: '0644' } + mode: '0644', + services: { 'smtp' => { 'type' => 'inet', 'priv' => 'n', 'chroot' => 'y', 'command' => 'smtpd', 'order' => '60_100' } }, } end shared_examples_for 'postfix::config::master class' do @@ -19,6 +20,13 @@ mode: '0644', ) end + context 'it configures services' do + it { + params[:services].each_pair do |k, v| + is_expected.to contain_postfix__config__service(k).with(v) + end + } + end context 'it includes concat_fragment' do it { is_expected.to contain_concat_fragment('postfix: master_cf_header') diff --git a/spec/classes/postfix_spec.rb b/spec/classes/postfix_spec.rb index a122633..45220eb 100644 --- a/spec/classes/postfix_spec.rb +++ b/spec/classes/postfix_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe 'postfix' do + let :default_params do + { services: {} } + end + shared_examples_for 'postfix server' do it { is_expected.to compile.with_all_deps } @@ -11,7 +15,7 @@ it { is_expected.to contain_class('postfix::service') } it { is_expected.to contain_package('postfix') - .with(ensure: 'present', + .with(ensure: 'installed', tag: 'postfix-packages') } end @@ -20,7 +24,9 @@ context "on #{os}" do let(:facts) { os_facts } - describe 'without parameters' do + describe 'with defaults' do + let(:params) { default_params } + it_behaves_like 'postfix server' it { is_expected.to contain_file('/etc/postfix/ssl') @@ -38,21 +44,25 @@ describe 'with server package' do let :params do - { packages: ['mypackage', 'postfix'] } + default_params.merge( + { packages: ['mypackage', 'postfix'] }, + ) end it_behaves_like 'postfix server' it { is_expected.to contain_package('mypackage') - .with(ensure: 'present', + .with(ensure: 'installed', tag: 'postfix-packages') } end describe 'with maps' do let :params do - { maps: { 'test-map' => {} } } + default_params.merge( + { maps: { 'test-map' => {} } }, + ) end it_behaves_like 'postfix server' @@ -63,7 +73,9 @@ describe 'with additional resources' do # use user resource to test (resource needs to be available) let :params do - { create_resources: { 'user' => { 'usertitle' => {} } } } + default_params.merge( + { create_resources: { 'user' => { 'usertitle' => {} } } }, + ) end it_behaves_like 'postfix server' diff --git a/spec/defines/config_service_spec.rb b/spec/defines/config_service_spec.rb index fa2e29d..de191e2 100644 --- a/spec/defines/config_service_spec.rb +++ b/spec/defines/config_service_spec.rb @@ -3,20 +3,18 @@ describe 'postfix::config::service' do let :default_params do - { master_cf_file: '/etc/postfix/master.cf' } + { master_cf_file: '/etc/postfix/master.cf', + order: '55', } end shared_examples 'postfix::config::service define' do - context 'it compiles with all dependencies' do - it { is_expected.to compile.with_all_deps } - end + it { is_expected.to compile.with_all_deps } - context 'it includes concat_fragment' do - it { - is_expected.to contain_concat_fragment('master.cf service: ' + title) - .with_target('/etc/postfix/master.cf') - } - end + it { + is_expected.to contain_concat_fragment('master.cf service: ' + title) + .with_target(params[:master_cf_file]) + .with_order(params[:order]) + } end on_supported_os.each do |os, os_facts| @@ -24,21 +22,22 @@ let(:facts) { os_facts } context 'whith defaults' do - let(:title) { 'debian' } + let(:title) { 'smtp' } let(:params) { default_params } it_behaves_like 'postfix::config::service define' end context 'whith non defaults' do - let(:title) { 'my-repo' } + let(:title) { 'smtp' } let :params do default_params.merge( type: 'fifo', command: 'fork', - service_names: ['bah'], + service_names: ['smtp'], order: '100', + master_cf_file: '/local/etc/postfix/master.cf', ) end diff --git a/spec/defines/map_spec.rb b/spec/defines/map_spec.rb index 6ad201a..f4fe248 100644 --- a/spec/defines/map_spec.rb +++ b/spec/defines/map_spec.rb @@ -5,6 +5,8 @@ let(:pre_condition) { 'service {"postfix": }' } let :default_params do { map_dir: '/etc/postfix/maps', + map_name: 'the-title', + type: 'hash', postmap_command: '/usr/sbin/postmap', owner: 'root', group: 'root', @@ -16,38 +18,34 @@ it { is_expected.to compile.with_all_deps } end - context 'it includes map file' do - it { - is_expected.to contain_concat('/etc/postfix/maps/' + title) - .with(owner: 'root', - mode: '0644') - .with_notify('Service[postfix]') - } - end - - context 'rebuild map' do - it { - is_expected.to contain_exec('rebuild map ' + title) - .with_command(%r{postmap}) - .with_require('Concat[/etc/postfix/maps/' + title + ']') - .with_notify('Service[postfix]') - .with_unless(%r{/etc/postfix/maps/#{title}.db}) - } - end + it { + is_expected.to contain_concat(params[:map_dir] + '/' + params[:map_name]) + .with(owner: params[:owner], + mode: params[:mode]) + .with_notify('Service[postfix]') + } + + it { + is_expected.to contain_exec('rebuild map ' + title) + .with_command(params[:postmap_command] + ' ' + params[:type] + ':' + params[:map_dir] + '/' + params[:map_name]) + .with_require('Concat[' + params[:map_dir] + '/' + params[:map_name] + ']') + .with_notify('Service[postfix]') + .with_unless("test #{params[:map_dir]}/#{params[:map_name]}.db -nt #{params[:map_dir]}/#{params[:map_name]}") + } end on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } context 'whith defaults' do - let(:title) { 'mymap' } + let(:title) { 'the-title' } let(:params) { default_params } it_behaves_like 'postfix::map define' end context 'whith content defined' do - let(:title) { 'map_with_content' } + let(:title) { 'the-title' } let :params do default_params.merge(contents: ['blah1', 'blah2']) end @@ -60,8 +58,8 @@ } end - context 'whith source defined' do - let(:title) { 'map_with_source' } + context 'with source defined' do + let(:title) { 'the-title' } let :params do default_params.merge(source: 'a_source') end @@ -75,23 +73,16 @@ end context 'whith btree map type' do - let(:title) { 'dbm_map_type' } + let(:title) { 'the-title' } let :params do default_params.merge(type: 'btree') end it_behaves_like 'postfix::map define' - - context 'rebuild btree map' do - it { - is_expected.to contain_exec('rebuild map dbm_map_type') - .with_command('/usr/sbin/postmap btree:/etc/postfix/maps/dbm_map_type') - } - end end context 'whith custom map path and name' do - let(:title) { 'custom_map_path_and_name' } + let(:title) { 'the-title' } let :params do default_params.merge( map_dir: '/blah/fasel', @@ -99,58 +90,11 @@ ) end - context 'it includes map file' do - it { - is_expected.to contain_concat('/blah/fasel/myname') - .with(owner: 'root', - group: 'root', - mode: '0644') - .with_notify('Service[postfix]') - } - end - - context 'rebuild map' do - it { - is_expected.to contain_exec('rebuild map custom_map_path_and_name') - .with_command('/usr/sbin/postmap hash:/blah/fasel/myname') - .with_require('Concat[/blah/fasel/myname]') - .with_notify('Service[postfix]') - .with_unless(%r{/blah/fasel/myname.(db|cdb|pag)}) - } - end - end - - context 'whith custom map path' do - let(:title) { 'custom_map_path' } - let :params do - default_params.merge( - map_dir: '/blah/fasel', - ) - end - - context 'it includes map file' do - it { - is_expected.to contain_concat('/blah/fasel/custom_map_path') - .with(owner: 'root', - group: 'root', - mode: '0644') - .with_notify('Service[postfix]') - } - end - - context 'rebuild map' do - it { - is_expected.to contain_exec('rebuild map custom_map_path') - .with_command('/usr/sbin/postmap hash:/blah/fasel/custom_map_path') - .with_require('Concat[/blah/fasel/custom_map_path]') - .with_notify('Service[postfix]') - .with_unless(%r{/blah/fasel/#{title}.db}) - } - end + it_behaves_like 'postfix::map define' end context 'whith custom postmap' do - let(:title) { 'custom_postmap' } + let(:title) { 'test-map' } let :params do default_params.merge( @@ -158,19 +102,11 @@ ) end - context 'rebuild map' do - it { - is_expected.to contain_exec('rebuild map custom_postmap') - .with_command('my_postmap_command hash:/etc/postfix/maps/custom_postmap') - .with_require('Concat[/etc/postfix/maps/custom_postmap]') - .with_notify('Service[postfix]') - .with_unless(%r{/etc/postfix/maps/#{title}.db}) - } - end + it_behaves_like 'postfix::map define' end context 'whith unknown map type' do - let(:title) { 'unknown_map_type' } + let(:title) { 'the-title' } let :params do default_params.merge(