diff --git a/.fixtures.yml b/.fixtures.yml index 3d0f23a..ca236c5 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,7 @@ fixtures: repositories: 'stdlib': repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' ref: '4.5.1' - 'file_concat': - repo: 'git://github.com/electrical/puppet-lib-file_concat.git' - ref: '1.0.1' symlinks: 'concat': '#{source_dir}' diff --git a/README.md b/README.md index 2913754..2bd2493 100644 --- a/README.md +++ b/README.md @@ -1,243 +1,241 @@ #concat ####Table of Contents 1. [Overview](#overview) 2. [Module Description - What the module does and why it is useful](#module-description) 3. [Setup - The basics of getting started with concat](#setup) * [What concat affects](#what-concat-affects) * [Beginning with concat](#beginning-with-concat) 4. [Usage - Configuration options and additional functionality](#usage) 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) * [Defines](#defines) * [Parameters](#parameters) * [Removed functionality](#removed-functionality) 6. [Limitations - OS compatibility, etc.](#limitations) 7. [Development - Guide for contributing to the module](#development) ##Overview The concat module lets you construct files from multiple ordered fragments of text. ##Module Description The concat module lets you gather `concat::fragment` resources from your other modules and order them into a coherent file through a single `concat` resource. -##Setup - -###What concat affects - -The concat module requires the [file_concat module](https://forge.puppetlabs.com/electrical/file_concat). If you don't have file_concat installed, concat installs it for you. - ###Beginning with concat To start using concat you need to create: * A concat{} resource for the final file. * One or more concat::fragment{}s. A minimal example might be: ~~~ concat { '/tmp/file': ensure => present, } concat::fragment { 'tmpfile': target => '/tmp/file', content => 'test contents', order => '01' } ~~~ ##Usage ###Maintain a list of the major modules on a node To maintain an motd file that lists the modules on one of your nodes, first create a class to frame up the file: ~~~ class motd { $motd = '/etc/motd' concat { $motd: owner => 'root', group => 'root', mode => '0644' } concat::fragment{ 'motd_header': target => $motd, content => "\nPuppet modules on this server:\n\n", order => '01' } # let local users add to the motd by creating a file called # /etc/motd.local concat::fragment{ 'motd_local': target => $motd, source => '/etc/motd.local', order => '15' } } # let other modules register themselves in the motd define motd::register($content="", $order='10') { if $content == "" { $body = $name } else { $body = $content } concat::fragment{ "motd_fragment_$name": target => '/etc/motd', order => $order, content => " -- $body\n" } } ~~~ Then, in the declarations for each module on the node, add `motd::register{ 'Apache': }` to register the module in the motd. ~~~ class apache { include apache::install, apache::config, apache::service motd::register{ 'Apache': } } ~~~ These two steps populate the /etc/motd file with a list of the installed and registered modules, which stays updated even if you just remove the registered modules' `include` lines. System administrators can append text to the list by writing to /etc/motd.local. When you're finished, the motd file will look something like this: ~~~ Puppet modules on this server: -- Apache -- MySQL ~~~ ##Reference ###Defines * `concat`: Manages a file, compiled from one or more text fragments. * `concat::fragment`: Manages a fragment of text to be compiled into a file. ###Parameters ####`concat` All the parameters listed below are optional. #####`backup` Specifies whether (and how) to back up the destination file before overwriting it. Your value gets passed on to Puppet's [native `file` resource](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-backup) for execution. Valid options: 'true', 'false', or a string representing either a target filebucket or a filename extension beginning with ".". Default value: 'puppet'. #####`ensure` Specifies whether the destination file should exist. Setting to 'absent' tells Puppet to delete the destination file if it exists, and negates the effect of any other parameters. Valid options: 'present' and 'absent'. Default value: 'present'. #####`force` Deprecated as of concat v2.0.0. Has no effect. #####`group` Specifies a permissions group for the destination file. Valid options: a string containing a group name. Default value: undefined. #####`mode` Specifies the permissions mode of the destination file. Valid options: a string containing a permission mode value in octal notation. Default value: '0644'. #####`order` Specifies a method for sorting your fragments by name within the destination file. Valid options: 'alpha' (e.g., '1, 10, 2') or 'numeric' (e.g., '1, 2, 10'). Default value: 'alpha'. You can override this setting for individual fragments by adjusting the `order` parameter in their `concat::fragment` declarations. #####`owner` Specifies the owner of the destination file. Valid options: a string containing a username. Default value: undefined. #####`path` Specifies a destination file for the combined fragments. Valid options: a string containing an absolute path. Default value: the title of your declared resource. #####`replace` Specifies whether to overwrite the destination file if it already exists. Valid options: 'true' and 'false'. Default value: 'true'. #####`validate_cmd` Specifies a validation command to apply to the destination file. Requires Puppet version 3.5 or newer. Valid options: a string to be passed to a file resource. Default value: undefined. #####`warn` Specifies whether to add a header message at the top of the destination file. Valid options: the booleans 'true' and 'false', or a string to serve as the header. Default value: 'false'. If you set 'warn' to 'true', `concat` adds the following message: ~~~ # This file is managed by Puppet. DO NOT EDIT. ~~~ ####`concat::fragment` Except where noted, all the below parameters are optional. #####`content` Supplies the content of the fragment. **Note**: You must supply either a `content` parameter or a `source` parameter. Valid options: a string. Default value: undef. #####`ensure` Deprecated as of concat v2.0.0. Has no effect. #####`order` Reorders your fragments within the destination file. Fragments that share the same order number are ordered by name. Valid options: a string (recommended) or an integer. Default value: '10'. #####`source` Specifies a file to read into the content of the fragment. **Note**: You must supply either a `content` parameter or a `source` parameter. Valid options: a string or an array, containing one or more Puppet URLs. Default value: undefined. #####`target` *Required.* Specifies the destination file of the fragment. Valid options: a string containing an absolute path. ###Removed functionality The following functionality existed in previous versions of the concat module, but were removed in version 2.0.0: Parameters removed from `concat`: * `ensure_newline` Parameters removed from `concat::fragment`: * `gnu` * `backup` * `group` * `mode` * `owner` The `concat::setup` class has also been removed. Prior to concat version 2.0.0, if you set the `warn` parameter to a string value of 'true', 'false', 'yes', 'no', 'on', or 'off', the module translated the string to the corresponding boolean value. In concat version 2.0.0 and newer, the `warn_header` parameter treats those values the same as other strings and uses them as the content of your header message. To avoid that, pass the 'true' and 'false' values as booleans instead of strings. ##Limitations This module has been tested on [all PE-supported platforms](https://forge.puppetlabs.com/supported#compat-matrix), and no issues have been identified. ##Development Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html) ###Contributors -To see who's already involved, see the [list of contributors.](https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors) \ No newline at end of file +Richard Pijnenburg ([@Richardp82](http://twitter.com/richardp82)) + +Joshua Hoblitt ([@jhoblitt](http://twitter.com/jhoblitt)) + +[More contributors.](https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors) diff --git a/lib/puppet/type/concat_file.rb b/lib/puppet/type/concat_file.rb new file mode 100644 index 0000000..bbac0db --- /dev/null +++ b/lib/puppet/type/concat_file.rb @@ -0,0 +1,154 @@ +require 'puppet/type/file/owner' +require 'puppet/type/file/group' +require 'puppet/type/file/mode' +require 'puppet/util/checksums' + +Puppet::Type.newtype(:concat_file) do + @doc = "Gets all the file fragments and puts these into the target file. + This will mostly be used with exported resources. + + example: + Concat_fragment <<| tag == 'unique_tag' |>> + + concat_file { '/tmp/file: + tag => 'unique_tag', # Mandatory + path => '/tmp/file', # Optional. If given it overrides the resource name + owner => 'root', # Optional. Default to undef + group => 'root', # Optional. Default to undef + mode => '0644' # Optional. Default to undef + order => 'numeric' # Optional, Default to 'numeric' + } + " + ensurable do + defaultvalues + + defaultto { :present } + end + + def exists? + self[:ensure] == :present + end + + newparam(:name, :namevar => true) do + desc "Resource name" + end + + newparam(:tag) do + desc "Tag reference to collect all concat_fragment's with the same tag" + end + + newparam(:path) do + desc "The output file" + defaultto do + resource.value(:name) + end + end + + newparam(:owner, :parent => Puppet::Type::File::Owner) do + desc "Desired file owner." + end + + newparam(:group, :parent => Puppet::Type::File::Group) do + desc "Desired file group." + end + + newparam(:mode, :parent => Puppet::Type::File::Mode) do + desc "Desired file mode." + end + + newparam(:order) do + desc "Controls the ordering of fragments. Can be set to alphabetical or numeric." + defaultto 'numeric' + end + + newparam(:backup) do + desc "Controls the filebucketing behavior of the final file and see File type reference for its use." + defaultto 'puppet' + end + + newparam(:replace) do + desc "Whether to replace a file that already exists on the local system." + defaultto true + end + + newparam(:validate_cmd) do + desc "Validates file." + end + + autorequire(:concat_fragment) do + catalog.resources.collect do |r| + if r.is_a?(Puppet::Type.type(:concat_fragment)) && r[:tag] == self[:tag] + r.name + end + end.compact + end + + def should_content + return @generated_content if @generated_content + @generated_content = "" + content_fragments = [] + + resources = catalog.resources.select do |r| + r.is_a?(Puppet::Type.type(:concat_fragment)) && r[:tag] == self[:tag] + end + + resources.each do |r| + content_fragments << ["#{r[:order]}___#{r[:name]}", fragment_content(r)] + end + + if self[:order] == 'numeric' + sorted = content_fragments.sort do |a, b| + def decompound(d) + d.split('___').map { |v| v =~ /^\d+$/ ? v.to_i : v } + end + + decompound(a[0]) <=> decompound(b[0]) + end + else + sorted = content_fragments.sort do |a, b| + def decompound(d) + d.split('___').first + end + + decompound(a[0]) <=> decompound(b[0]) + end + end + + @generated_content = sorted.map { |cf| cf[1] }.join + + @generated_content + end + + def fragment_content(r) + if r[:content].nil? == false + fragment_content = r[:content] + elsif r[:source].nil? == false + @source = nil + Array(r[:source]).each do |source| + if Puppet::FileServing::Metadata.indirection.find(source) + @source = source + break + end + end + self.fail "Could not retrieve source(s) #{r[:source].join(", ")}" unless @source + tmp = Puppet::FileServing::Content.indirection.find(@source, :environment => catalog.environment) + fragment_content = tmp.content unless tmp.nil? + end + fragment_content + end + + def eval_generate + file_opts = { + :ensure => self[:ensure] == :absent ? :absent : :file, + :content => self.should_content, + } + + [:path, :owner, :group, :mode, :replace, :backup].each do |param| + unless self[param].nil? + file_opts[param] = self[param] + end + end + + [Puppet::Type.type(:file).new(file_opts)] + end +end diff --git a/lib/puppet/type/concat_fragment.rb b/lib/puppet/type/concat_fragment.rb new file mode 100644 index 0000000..3a1e722 --- /dev/null +++ b/lib/puppet/type/concat_fragment.rb @@ -0,0 +1,48 @@ +Puppet::Type.newtype(:concat_fragment) do + @doc = "Create a concat fragment to be used by concat. + the `concat_fragment` type creates a file fragment to be collected by concat based on the tag. + The example is based on exported resources. + + Example: + @@concat_fragment { \"uniqe_name_${::fqdn}\": + tag => 'unique_name', + order => 10, # Optional. Default to 10 + content => 'some content' # OR + content => template('template.erb') # OR + source => 'puppet:///path/to/file' + } + " + + newparam(:name, :namevar => true) do + desc "Unique name" + end + + newparam(:content) do + desc "Content" + end + + newparam(:source) do + desc "Source" + end + + newparam(:order) do + desc "Order" + defaultto '10' + validate do |val| + fail Puppet::ParseError, '$order is not a string or integer.' if !(val.is_a? String or val.is_a? Integer) + fail Puppet::ParseError, "Order cannot contain '/', ':', or '\n'." if val.to_s =~ /[:\n\/]/ + end + end + + newparam(:tag) do + desc "Tag name to be used by concat to collect all concat_fragments by tag name" + end + + validate do + # Check if either source or content is set. raise error if none is set + fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil? + + # Check if both are set, if so rais error + fail Puppet::ParseError, "Can't use 'source' and 'content' at the same time" if !self[:source].nil? && !self[:content].nil? + end +end diff --git a/manifests/fragment.pp b/manifests/fragment.pp index fabc359..9cfae66 100644 --- a/manifests/fragment.pp +++ b/manifests/fragment.pp @@ -1,55 +1,55 @@ # == Define: concat::fragment # -# Creates a file_fragment in the catalogue +# Creates a concat_fragment in the catalogue # # === Options: # # [*target*] # The file that these fragments belong to # [*content*] # If present puts the content into the file # [*source*] # If content was not specified, use the source # [*order*] # By default all files gets a 10_ prefix in the directory you can set it to # anything else using this to influence the order of the content in the file # define concat::fragment( $target, $ensure = undef, $content = undef, $source = undef, $order = '10', ) { validate_string($target) if $ensure != undef { warning('The $ensure parameter to concat::fragment is deprecated and has no effect.') } validate_string($content) if !(is_string($source) or is_array($source)) { fail('$source is not a string or an Array.') } if !(is_string($order) or is_integer($order)) { fail('$order is not a string or integer.') } elsif (is_string($order) and $order =~ /[:\n\/]/) { fail("Order cannot contain '/', ':', or '\n'.") } if ! ($content or $source) { crit('No content, source or symlink specified') } elsif ($content and $source) { fail("Can't use 'source' and 'content' at the same time") } $safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM') - file_fragment { $name: + concat_fragment { $name: tag => $safe_target_name, order => $order, content => $content, source => $source, } } diff --git a/manifests/init.pp b/manifests/init.pp index 83eb191..986e6a7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,124 +1,113 @@ # == Define: concat # # Sets up so that you can use fragments to build a final config file, # # === Options: # # [*ensure*] # Present/Absent # [*path*] # The path to the final file. Use this in case you want to differentiate # between the name of a resource and the file path. Note: Use the name you # provided in the target of your fragments. # [*owner*] # Who will own the file # [*group*] # Who will own the file # [*mode*] # The mode of the final file # [*warn_header*] # Adds a normal shell style comment top of the file indicating that it is # built by puppet # [*backup*] # Controls the filebucketing behavior of the final file and see File type # reference for its use. Defaults to 'puppet' # [*replace*] # Whether to replace a file that already exists on the local system # [*order*] # Select whether to order associated fragments by 'alpha' or 'numeric'. # Defaults to 'alpha'. # -# === Actions: -# * Creates a file_concat resource from the electrical/puppet-lib-file_concat library. -# * Creates file_fragment resources from electrical/puppet-lib-file_concat -# -# === Aliases: -# -# * The exec can notified using Exec["concat_/path/to/file"] or -# Exec["concat_/path/to/directory"] -# * The final file can be referenced as File["/path/to/file"] or -# File["concat_/path/to/file"] -# define concat( $ensure = 'present', $path = $name, $owner = undef, $group = undef, $mode = '0644', $warn = false, $force = undef, $backup = 'puppet', $replace = true, $order = 'alpha', $validate_cmd = undef, ) { validate_re($ensure, '^present$|^absent$') validate_absolute_path($path) validate_string($owner) validate_string($group) validate_string($mode) if ! (is_string($warn) or $warn == true or $warn == false) { fail('$warn is not a string or boolean') } if ! is_bool($backup) and ! is_string($backup) { fail('$backup must be string or bool!') } validate_bool($replace) validate_re($order, '^alpha$|^numeric$') if $validate_cmd and ! is_string($validate_cmd) { fail('$validate_cmd must be a string') } if $force != undef { warning('The $force parameter to concat is deprecated and has no effect.') } $safe_name = regsubst($name, '[/:\n\s]', '_', 'G') $default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n" case $warn { true: { $warn_message = $default_warn_message $_append_header = true } false: { $warn_message = '' $_append_header = false } default: { $warn_message = $warn $_append_header = true } } if $ensure == 'present' { - file_concat { $name: + concat_file { $name: tag => $safe_name, path => $path, owner => $owner, group => $group, mode => $mode, replace => $replace, backup => $backup, order => $order, validate_cmd => $validate_cmd, } if $_append_header { - file_fragment { "#{$name}_header": + concat_fragment { "#{$name}_header": tag => $safe_name, content => $warn_message, order => '0', } } } else { - file_concat { $name: + concat_file { $name: ensure => $ensure, tag => $safe_name, path => $path, backup => $backup, } } } diff --git a/metadata.json b/metadata.json index 9cd3909..fd7986f 100644 --- a/metadata.json +++ b/metadata.json @@ -1,111 +1,110 @@ { "name": "puppetlabs-concat", "version": "2.0.0", "author": "Puppet Labs", "summary": "Construct files from multiple fragments.", "license": "Apache-2.0", "source": "https://github.com/puppetlabs/puppetlabs-concat", "project_page": "https://github.com/puppetlabs/puppetlabs-concat", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "10 SP4", "11 SP1", "12" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "6", "7" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "10.04", "12.04", "14.04" ] }, { "operatingsystem": "Solaris", "operatingsystemrelease": [ "10", "11" ] }, { "operatingsystem": "Windows", "operatingsystemrelease": [ "Server 2003 R2", "Server 2008 R2", "Server 2012", "Server 2012 R2" ] }, { "operatingsystem": "AIX", "operatingsystemrelease": [ "5.3", "6.1", "7.1" ] }, { "operatingsystem": "OSX", "operatingsystemrelease": [ "10.9" ] } ], "requirements": [ { "name": "pe", "version_requirement": ">= 3.7.0 < 4.0" }, { "name": "puppet", "version_requirement": "3.x" } ], "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}, - {"name":"electrical/file_concat","version_requirement":"1.0.1"} ] } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 56c6ea7..d27df7d 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,69 +1,61 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' require 'acceptance/specinfra_stubs' unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes foss_opts = {:default_action => 'gem_install'} if default.is_pe?; then install_pe; else install_puppet(foss_opts); end hosts.each do |host| on hosts, "mkdir -p #{host['distmoduledir']}" if host['platform'] =~ /sles-1/i || host['platform'] =~ /solaris-1/i get_deps = <<-EOS package{'wget':} exec{'download-stdlib': command => "wget -P /root/ https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz --no-check-certificate", path => ['/opt/csw/bin/','/usr/bin/'] } - exec{'download-file_concat': - command => "wget -P /root/ https://forgeapi.puppetlabs.com/v3/files/electrical-file_concat-1.0.1.tar.gz --no-check-certificate", - path => ['/opt/csw/bin/','/usr/bin/'] - } EOS apply_manifest_on(host, get_deps) # have to use force otherwise it checks ssl cert even though it is a local file on host, puppet('module install /root/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} - on host, puppet('module install /root/electrical-file_concat-1.0.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} elsif host['platform'] =~ /windows/i on host, shell('curl -k -o c:/puppetlabs-stdlib-4.5.1.tar.gz https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz') on host, puppet('module install c:/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} - on host, shell('curl -k -o c:/electrical-file_concat-1.0.1.tar.gz https://forgeapi.puppetlabs.com/v3/files/electrical-file_concat-1.0.1.tar.gz') - on host, puppet('module install c:/electrical-file_concat-1.0.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} else on host, puppet('module install puppetlabs-stdlib'), {:acceptable_exit_codes => [0, 1]} - on host, puppet('module install electrical-file_concat'), {:acceptable_exit_codes => [0, 1]} end end end RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # Configure all nodes in nodeset c.before :suite do hosts.each do |host| copy_module_to(host, :source => proj_root, :module_name => 'concat') end end c.before(:all) do shell('mkdir -p /tmp/concat') end c.after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end c.treat_symbols_as_metadata_keys_with_true_values = true end diff --git a/spec/unit/defines/concat_fragment_spec.rb b/spec/unit/defines/concat_fragment_spec.rb index 98be58a..317b02c 100644 --- a/spec/unit/defines/concat_fragment_spec.rb +++ b/spec/unit/defines/concat_fragment_spec.rb @@ -1,115 +1,115 @@ require 'spec_helper' describe 'concat::fragment', :type => :define do shared_examples 'fragment' do |title, params| params = {} if params.nil? p = { :content => nil, :source => nil, :order => 10, }.merge(params) id = 'root' gid = 'root' let(:title) { title } let(:params) { params } let(:pre_condition) do "concat{ '#{p[:target]}': }" end it do should contain_concat(p[:target]) - should contain_file_concat(p[:target]) - should contain_file_fragment(title) + should contain_concat_file(p[:target]) + should contain_concat_fragment(title) end end context 'title' do ['0', '1', 'a', 'z'].each do |title| it_behaves_like 'fragment', title, { :target => '/etc/motd', :content => "content for #{title}" } end end # title context 'target =>' do ['./etc/motd', 'etc/motd', 'motd_header'].each do |target| context target do it_behaves_like 'fragment', target, { :target => '/etc/motd', :content => "content for #{target}" } end end context 'false' do let(:title) { 'motd_header' } let(:params) {{ :target => false }} it 'should fail' do expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # target => context 'content =>' do ['', 'ashp is our hero'].each do |content| context content do it_behaves_like 'fragment', 'motd_header', { :content => content, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:params) {{ :content => false, :target => '/etc/motd' }} it 'should fail' do expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # content => context 'source =>' do ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source| context source do it_behaves_like 'fragment', 'motd_header', { :source => source, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:params) {{ :source => false, :target => '/etc/motd' }} it 'should fail' do expect { catalogue }.to raise_error(Puppet::Error, /is not a string or an Array/) end end end # source => context 'more than one content source' do context 'source and content' do let(:title) { 'motd_header' } let(:params) do { :target => '/etc/motd', :source => '/foo', :content => 'bar', } end it 'should fail' do expect { catalogue }.to raise_error(Puppet::Error, /Can't use 'source' and 'content' at the same time/) end end end # more than one content source end