Skip to content

Commit cd03959

Browse files
committed
re-add removed params for backwards compatibility
1 parent ea5af52 commit cd03959

File tree

5 files changed

+84
-46
lines changed

5 files changed

+84
-46
lines changed

manifests/fragment.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
#
1717
define concat::fragment(
1818
$target,
19+
$ensure = undef,
1920
$content = undef,
2021
$source = undef,
2122
$order = '10',
2223
) {
2324
validate_string($target)
25+
26+
if $ensure != undef {
27+
warning('The $ensure parameter to concat::fragment is deprecated and has no effect.')
28+
}
29+
2430
validate_string($content)
2531
if !(is_string($source) or is_array($source)) {
2632
fail('$source is not a string or an Array.')

manifests/init.pp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
$owner = undef,
4747
$group = undef,
4848
$mode = '0644',
49-
$warn_header = false,
49+
$warn = false,
50+
$force = undef,
5051
$backup = 'puppet',
5152
$replace = true,
5253
$order = 'alpha',
@@ -57,8 +58,8 @@
5758
validate_string($owner)
5859
validate_string($group)
5960
validate_string($mode)
60-
if ! (is_string($warn_header) or $warn_header == true or $warn_header == false) {
61-
fail('$warn_header is not a string or boolean')
61+
if ! (is_string($warn) or $warn == true or $warn == false) {
62+
fail('$warn is not a string or boolean')
6263
}
6364
if ! is_bool($backup) and ! is_string($backup) {
6465
fail('$backup must be string or bool!')
@@ -69,10 +70,14 @@
6970
fail('$validate_cmd must be a string')
7071
}
7172

73+
if $force != undef {
74+
warning('The $force parameter to concat is deprecated and has no effect.')
75+
}
76+
7277
$safe_name = regsubst($name, '[/:\n\s]', '_', 'G')
7378
$default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
7479

75-
case $warn_header {
80+
case $warn {
7681
true: {
7782
$warn_message = $default_warn_message
7883
$append_header = true
@@ -81,7 +86,7 @@
8186
$warn_message = ''
8287
}
8388
default: {
84-
$warn_message = $warn_header
89+
$warn_message = $warn
8590
$append_header = true
8691
}
8792
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'deprecation warnings' do
4+
basedir = default.tmpdir('concat')
5+
6+
shared_examples 'has_warning' do |pp, w|
7+
it 'applies the manifest twice with a stderr regex' do
8+
expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/#{Regexp.escape(w)}/m)
9+
expect(apply_manifest(pp, :catch_changes => true).stderr).to match(/#{Regexp.escape(w)}/m)
10+
end
11+
end
12+
13+
context 'concat force parameter' do
14+
pp = <<-EOS
15+
concat { '#{basedir}/file':
16+
force => false,
17+
}
18+
concat::fragment { 'foo':
19+
target => '#{basedir}/file',
20+
content => 'bar',
21+
}
22+
EOS
23+
w = 'The $force parameter to concat is deprecated and has no effect.'
24+
25+
it_behaves_like 'has_warning', pp, w
26+
end
27+
28+
context 'concat::fragment ensure parameter' do
29+
context 'target file exists' do
30+
pp = <<-EOS
31+
concat { '#{basedir}/file':
32+
}
33+
concat::fragment { 'foo':
34+
target => '#{basedir}/file',
35+
ensure => false,
36+
content => 'bar',
37+
}
38+
EOS
39+
w = 'The $ensure parameter to concat::fragment is deprecated and has no effect.'
40+
41+
it_behaves_like 'has_warning', pp, w
42+
end
43+
end
44+
end

spec/acceptance/warn_header_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'spec_helper_acceptance'
22

3-
describe 'concat warn_header =>' do
3+
describe 'concat warn =>' do
44
basedir = default.tmpdir('concat')
55
context 'true should enable default warning message' do
66
pp = <<-EOS
77
concat { '#{basedir}/file':
8-
warn_header => true,
8+
warn => true,
99
}
1010
1111
concat::fragment { '1':
@@ -38,7 +38,7 @@
3838
context 'false should not enable default warning message' do
3939
pp = <<-EOS
4040
concat { '#{basedir}/file':
41-
warn_header => false,
41+
warn => false,
4242
}
4343
4444
concat::fragment { '1':
@@ -71,7 +71,7 @@
7171
context '# foo should overide default warning message' do
7272
pp = <<-EOS
7373
concat { '#{basedir}/file':
74-
warn_header => "# foo\n",
74+
warn => "# foo\n",
7575
}
7676
7777
concat::fragment { '1':

spec/unit/defines/concat_spec.rb

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
:owner => nil,
1414
:group => nil,
1515
:mode => '0644',
16-
:warn_header => false,
17-
#:force => false,
16+
:warn => false,
1817
:backup => 'puppet',
1918
:replace => true,
2019
}.merge(params)
@@ -168,17 +167,17 @@
168167
end
169168
end # mode =>
170169

171-
context 'warn_header =>' do
170+
context 'warn =>' do
172171
[true, false, '# foo'].each do |warn|
173172
context warn do
174-
it_behaves_like 'concat', '/etc/foo.bar', { :warn_header => warn }
173+
it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
175174
end
176175
end
177176

178177
context '(stringified boolean)' do
179178
['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
180179
context warn do
181-
it_behaves_like 'concat', '/etc/foo.bar', { :warn_header => warn }
180+
it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
182181

183182
it 'should create a warning' do
184183
skip('rspec-puppet support for testing warning()')
@@ -189,29 +188,13 @@
189188

190189
context '123' do
191190
let(:title) { '/etc/foo.bar' }
192-
let(:params) {{ :warn_header => 123 }}
191+
let(:params) {{ :warn => 123 }}
193192
it 'should fail' do
194193
expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/)
195194
end
196195
end
197196
end # warn =>
198197

199-
#context 'force =>' do
200-
# [true, false].each do |force|
201-
# context force do
202-
# it_behaves_like 'concat', '/etc/foo.bar', { :force => force }
203-
# end
204-
# end
205-
206-
# context '123' do
207-
# let(:title) { '/etc/foo.bar' }
208-
# let(:params) {{ :force => 123 }}
209-
# it 'should fail' do
210-
# expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
211-
# end
212-
# end
213-
#end # force =>
214-
215198
context 'backup =>' do
216199
context 'reverse' do
217200
it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
@@ -250,19 +233,19 @@
250233
end
251234
end # replace =>
252235

253-
#context 'order =>' do
254-
# ['alpha', 'numeric'].each do |order|
255-
# context order do
256-
# it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
257-
# end
258-
# end
259-
260-
# context 'invalid' do
261-
# let(:title) { '/etc/foo.bar' }
262-
# let(:params) {{ :order => 'invalid' }}
263-
# it 'should fail' do
264-
# expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
265-
# end
266-
# end
267-
#end # order =>
236+
context 'order =>' do
237+
['alpha', 'numeric'].each do |order|
238+
context order do
239+
it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
240+
end
241+
end
242+
243+
context 'invalid' do
244+
let(:title) { '/etc/foo.bar' }
245+
let(:params) {{ :order => 'invalid' }}
246+
it 'should fail' do
247+
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
248+
end
249+
end
250+
end # order =>
268251
end

0 commit comments

Comments
 (0)