Skip to content

Commit 6bacf75

Browse files
committed
stdlib::manage: Also permit templates for concat::fragment
1 parent 50a6b6b commit 6bacf75

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

.fixtures.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ fixtures:
55
provision: 'https://github.com/puppetlabs/provision.git'
66
symlinks:
77
stdlib: "#{source_dir}"
8-
test: "#{source_dir}/spec/fixtures/test"
8+
test: "#{source_dir}/spec/fixtures/test"
9+
forge_modules:
10+
concat: "puppetlabs/concat"

manifests/manage.pp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@
7070
$create_resources.each |$type, $resources| {
7171
$resources.each |$title, $attributes| {
7272
case $type {
73-
'file': {
73+
'file', 'concat::fragment': {
7474
# sanity checks
7575
# epp, erb and content are exclusive
7676
if 'epp' in $attributes and 'content' in $attributes {
77-
fail("You can not set 'epp' and 'content' for file ${title}")
77+
fail("You can not set 'epp' and 'content' for ${type} ${title}")
7878
}
7979
if 'erb' in $attributes and 'content' in $attributes {
80-
fail("You can not set 'erb' and 'content' for file ${title}")
80+
fail("You can not set 'erb' and 'content' for ${type} ${title}")
8181
}
8282
if 'erb' in $attributes and 'epp' in $attributes {
83-
fail("You can not set 'erb' and 'epp' for file ${title}")
83+
fail("You can not set 'erb' and 'epp' for ${type} ${title}")
8484
}
8585

8686
if 'epp' in $attributes {
@@ -91,20 +91,20 @@
9191
$content = epp($attributes['epp']['template'])
9292
}
9393
} else {
94-
fail("No template configured for epp for file ${title}")
94+
fail("No template configured for epp for ${type} ${title}")
9595
}
9696
} elsif 'erb' in $attributes {
9797
if 'template' in $attributes['erb'] {
9898
$content = template($attributes['erb']['template'])
9999
} else {
100-
fail("No template configured for erb for file ${title}")
100+
fail("No template configured for erb for ${type} ${title}")
101101
}
102102
} elsif 'content' in $attributes {
103103
$content = $attributes['content']
104104
} else {
105105
$content = undef
106106
}
107-
file { $title:
107+
$type { $title:
108108
* => $attributes - 'erb' - 'epp' - 'content',
109109
content => $content,
110110
}

spec/classes/manage_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@
3737
}
3838
}
3939
},
40+
'concat' => {
41+
'/tmp/filename' => {
42+
'ensure' => 'present',
43+
}
44+
},
45+
'concat::fragment' => {
46+
'rawcontent' => {
47+
'target' => '/tmp/filename',
48+
'content' => 'test content',
49+
},
50+
'eppcontent' => {
51+
'target' => '/tmp/filename',
52+
'epp' => {
53+
'template' => 'profile/motd.epp'
54+
},
55+
},
56+
'erbcontent' => {
57+
'target' => '/tmp/filename',
58+
'erb' => {
59+
'template' => 'profile/information.erb'
60+
},
61+
}
62+
},
4063
'package' => {
4164
'example' => {
4265
'ensure' => 'installed',
@@ -58,6 +81,10 @@
5881
it { is_expected.to contain_file('/etc/motd.d/hello').with_content('I say Hi').with_notify('Service[sshd]') }
5982
it { is_expected.to contain_file('/etc/motd').with_content(%r{I am an epp template}) }
6083
it { is_expected.to contain_file('/etc/information').with_content(%r{I am an erb template}) }
84+
it { is_expected.to contain_concat('/tmp/filename') }
85+
it { is_expected.to contain_concat__fragment('rawcontent').with_content('test content') }
86+
it { is_expected.to contain_concat__fragment('eppcontent').with_content(%r{I am an epp template}) }
87+
it { is_expected.to contain_concat__fragment('erbcontent').with_content(%r{I am an erb template}) }
6188
it { is_expected.to contain_package('example').with_ensure('installed').that_subscribes_to(['Service[sshd]', 'File[/etc/motd.d]']) }
6289
end
6390
end

0 commit comments

Comments
 (0)