Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / defines / concat_fragment_spec.rb
1 require 'spec_helper'
2
3 describe 'concat::fragment' do
4   shared_examples 'fragment' do |title, params|
5     params = {} if params.nil?
6
7     p = {
8       content: nil,
9       source: nil,
10       order: 10,
11     }.merge(params)
12
13     let(:title) { title }
14     let(:params) { params }
15     let(:pre_condition) do
16       "concat{ '#{p[:target]}': }"
17     end
18
19     it do
20       is_expected.to contain_concat(p[:target])
21     end
22     it do
23       is_expected.to contain_concat_file(p[:target])
24     end
25     it do
26       is_expected.to contain_concat_fragment(title)
27     end
28   end
29
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}"
34     end
35   end
36   # title
37
38   context 'when target =>' do
39     ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
40       context target do
41         it_behaves_like 'fragment', target, target: '/etc/motd',
42                                             content: "content for #{target}"
43       end
44     end
45
46     context 'when false' do
47       let(:title) { 'motd_header' }
48       let(:params) { { target: false } }
49
50       it 'fails' do
51         expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'target' expects a .*String.*})
52       end
53     end
54   end
55   # target =>
56
57   context 'when content =>' do
58     ['', 'ashp is our hero'].each do |content|
59       context content do
60         it_behaves_like 'fragment', 'motd_header', content: content,
61                                                    target: '/etc/motd'
62       end
63     end
64
65     context 'when false' do
66       let(:title) { 'motd_header' }
67       let(:params) { { content: false, target: '/etc/motd' } }
68
69       it 'fails' do
70         expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'content' expects a .*String.*})
71       end
72     end
73   end
74   # content =>
75
76   context 'when source =>' do
77     ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
78       context source do
79         it_behaves_like 'fragment', 'motd_header',           source: source,
80                                                              target: '/etc/motd'
81       end
82     end
83
84     context 'when false' do
85       let(:title) { 'motd_header' }
86       let(:params) { { source: false, target: '/etc/motd' } }
87
88       it 'fails' do
89         expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'source' expects a .*String.*Array.*})
90       end
91     end
92   end
93   # source =>
94
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,
99                                                              target: '/etc/motd'
100       end
101     end
102
103     context 'when false' do
104       let(:title) { 'motd_header' }
105       let(:params) { { order: false, target: '/etc/motd' } }
106
107       it 'fails' do
108         expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*Boolean.*})
109       end
110     end
111
112     context 'when 123:456' do
113       let(:title) { 'motd_header' }
114       let(:params) { { order: '123:456', target: '/etc/motd' } }
115
116       it 'fails' do
117         expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
118       end
119     end
120     context 'when 23/456' do
121       let(:title) { 'motd_header' }
122       let(:params) { { order: '123/456', target: '/etc/motd' } }
123
124       it 'fails' do
125         expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
126       end
127     end
128     context 'when 123\n456' do
129       let(:title) { 'motd_header' }
130       let(:params) { { order: "123\n456", target: '/etc/motd' } }
131
132       it 'fails' do
133         expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
134       end
135     end
136   end
137   # order =>
138
139   context 'with more than one content source' do
140     context 'with source and content' do
141       let(:title) { 'motd_header' }
142       let(:params) do
143         {
144           target: '/etc/motd',
145           source: '/foo',
146           content: 'bar',
147         }
148       end
149
150       it 'fails' do
151         expect { catalogue }.to raise_error(Puppet::Error, %r{Can\'t use \'source\' and \'content\' at the same time}m)
152       end
153     end
154   end
155   # more than one content source
156 end