Merge pull request #134 from apenney/fix-absent

Fix ensure => absent with path => set.
This commit is contained in:
Ashley Penney 2014-01-23 09:28:59 -08:00
commit b592726dc2
5 changed files with 66 additions and 11 deletions

View file

@ -2,6 +2,6 @@ fixtures:
repositories:
'stdlib':
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '3.0.0'
ref: '4.0.0'
symlinks:
'concat': '#{source_dir}'

View file

@ -6,4 +6,4 @@ license 'Apache 2.0'
summary 'Concat module'
description 'Concat module'
project_page 'http://github.com/puppetlabs/puppetlabs-concat'
dependency 'puppetlabs/stdlib', '>= 3.0.0'
dependency 'puppetlabs/stdlib', '>= 4.0.0'

View file

@ -29,16 +29,13 @@ define concat::fragment(
$content = undef,
$source = undef,
$order = 10,
$ensure = 'present',
$ensure = undef,
$mode = undef,
$owner = undef,
$group = undef,
$backup = undef
) {
validate_string($target)
if ! ($ensure in [ 'present', 'absent' ]) {
warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.')
}
validate_string($content)
if !(is_string($source) or is_array($source)) {
fail('$source is not a string or an Array.')
@ -56,6 +53,14 @@ define concat::fragment(
if $backup {
warning('The $backup parameter to concat::fragment is deprecated and has no effect')
}
if $ensure == undef {
$_ensure = getparam(Concat[$target], 'ensure')
} else {
if ! ($ensure in [ 'present', 'absent' ]) {
warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.')
}
$_ensure = $ensure
}
include concat::setup
@ -71,18 +76,18 @@ define concat::fragment(
# be paranoid and only allow the fragment's file resource's ensure param to
# be file, absent, or a file target
$safe_ensure = $ensure ? {
$safe_ensure = $_ensure ? {
'' => 'file',
undef => 'file',
'file' => 'file',
'present' => 'file',
'absent' => 'absent',
default => $ensure,
default => $_ensure,
}
# if it looks line ensure => /target syntax was used, fish that out
if ! ($ensure in ['', 'present', 'absent', 'file' ]) {
$ensure_target = $ensure
if ! ($_ensure in ['', 'present', 'absent', 'file' ]) {
$ensure_target = $_ensure
}
# the file type's semantics only allows one of: ensure => /target, content,

View file

@ -206,7 +206,7 @@ define concat(
force => true,
}
file { $name:
file { $path:
ensure => absent,
backup => $backup,
}

View file

@ -151,4 +151,54 @@ describe 'basic concat test' do
it { should contain '2' }
end
end
context 'ensure' do
context 'works when set to present with path set' do
pp="
concat { 'file':
ensure => present,
path => '/tmp/concat/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
it_behaves_like 'successfully_applied', pp
describe file('/tmp/concat/file') do
it { should be_file }
it { should be_mode 644 }
it { should contain '1' }
end
end
context 'works when set to absent with path set' do
pp="
concat { 'file':
ensure => absent,
path => '/tmp/concat/file',
mode => '0644',
}
concat::fragment { '1':
target => 'file',
content => '1',
order => '01',
}
"
# Can't used shared examples as this will always trigger the exec when
# absent is set.
it 'applies the manifest twice with no stderr' do
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
end
describe file('/tmp/concat/file') do
it { should_not be_file }
end
end
end
end