3 describe 'concat::fragment' do
4 shared_examples 'fragment' do |title, params|
5 params = {} if params.nil?
14 let(:params) { params }
15 let(:pre_condition) do
16 "concat{ '#{p[:target]}': }"
20 is_expected.to contain_concat(p[:target])
23 is_expected.to contain_concat_file(p[:target])
26 is_expected.to contain_concat_fragment(title)
30 context 'when title' do
31 ['0', '1', 'a', 'z'].each do |title|
32 it_behaves_like 'fragment', title, target: '/etc/motd',
33 content: "content for #{title}"
38 context 'when target =>' do
39 ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
41 it_behaves_like 'fragment', target, target: '/etc/motd',
42 content: "content for #{target}"
46 context 'when false' do
47 let(:title) { 'motd_header' }
48 let(:params) { { target: false } }
51 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'target' expects a .*String.*})
57 context 'when content =>' do
58 ['', 'ashp is our hero'].each do |content|
60 it_behaves_like 'fragment', 'motd_header', content: content,
65 context 'when false' do
66 let(:title) { 'motd_header' }
67 let(:params) { { content: false, target: '/etc/motd' } }
70 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'content' expects a .*String.*})
76 context 'when source =>' do
77 ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
79 it_behaves_like 'fragment', 'motd_header', source: source,
84 context 'when false' do
85 let(:title) { 'motd_header' }
86 let(:params) { { source: false, target: '/etc/motd' } }
89 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'source' expects a .*String.*Array.*})
95 context 'when order =>' do
96 ['', '42', 'a', 'z'].each do |order|
97 context "'#{order}'" do
98 it_behaves_like 'fragment', 'motd_header', order: order,
103 context 'when false' do
104 let(:title) { 'motd_header' }
105 let(:params) { { order: false, target: '/etc/motd' } }
108 expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*Boolean.*})
112 context 'when 123:456' do
113 let(:title) { 'motd_header' }
114 let(:params) { { order: '123:456', target: '/etc/motd' } }
117 expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
120 context 'when 23/456' do
121 let(:title) { 'motd_header' }
122 let(:params) { { order: '123/456', target: '/etc/motd' } }
125 expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
128 context 'when 123\n456' do
129 let(:title) { 'motd_header' }
130 let(:params) { { order: "123\n456", target: '/etc/motd' } }
133 expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
139 context 'with more than one content source' do
140 context 'with source and content' do
141 let(:title) { 'motd_header' }
151 expect { catalogue }.to raise_error(Puppet::Error, %r{Can\'t use \'source\' and \'content\' at the same time}m)
155 # more than one content source