Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / replace_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'replacement of' do
4   basedir = default.tmpdir('concat')
5   context 'file' do
6     context 'should not succeed' do
7       before(:all) do
8         pp = <<-EOS
9           file { '#{basedir}':
10             ensure => directory,
11           }
12           file { '#{basedir}/file':
13             content => "file exists\n"
14           }
15         EOS
16         apply_manifest(pp)
17       end
18       pp = <<-EOS
19         concat { '#{basedir}/file':
20           replace => false,
21         }
22
23         concat::fragment { '1':
24           target  => '#{basedir}/file',
25           content => '1',
26         }
27
28         concat::fragment { '2':
29           target  => '#{basedir}/file',
30           content => '2',
31         }
32       EOS
33
34       it 'applies the manifest twice with no stderr' do
35         apply_manifest(pp, :catch_failures => true)
36         apply_manifest(pp, :catch_changes => true)
37       end
38
39       describe file("#{basedir}/file") do
40         it { should be_file }
41         its(:content) {
42           should match 'file exists'
43           should_not match '1'
44           should_not match '2'
45         }
46       end
47     end
48
49     context 'should succeed' do
50       before(:all) do
51         pp = <<-EOS
52           file { '#{basedir}':
53             ensure => directory,
54           }
55           file { '#{basedir}/file':
56             content => "file exists\n"
57           }
58         EOS
59         apply_manifest(pp)
60       end
61       pp = <<-EOS
62         concat { '#{basedir}/file':
63           replace => true,
64         }
65
66         concat::fragment { '1':
67           target  => '#{basedir}/file',
68           content => '1',
69         }
70
71         concat::fragment { '2':
72           target  => '#{basedir}/file',
73           content => '2',
74         }
75       EOS
76
77       it 'applies the manifest twice with no stderr' do
78         apply_manifest(pp, :catch_failures => true)
79         apply_manifest(pp, :catch_changes => true)
80       end
81
82       describe file("#{basedir}/file") do
83         it { should be_file }
84         its(:content) {
85           should_not match 'file exists'
86           should match '1'
87           should match '2'
88         }
89       end
90     end
91   end # file
92
93   context 'symlink', :unless => (fact("osfamily") == "windows") do
94     context 'should not succeed' do
95       # XXX the core puppet file type will replace a symlink with a plain file
96       # when using ensure => present and source => ... but it will not when using
97       # ensure => present and content => ...; this is somewhat confusing behavior
98       before(:all) do
99         pp = <<-EOS
100           file { '#{basedir}':
101             ensure => directory,
102           }
103           file { '#{basedir}/file':
104             ensure => link,
105             target => '#{basedir}/dangling',
106           }
107         EOS
108         apply_manifest(pp)
109       end
110
111       pp = <<-EOS
112         concat { '#{basedir}/file':
113           replace => false,
114         }
115
116         concat::fragment { '1':
117           target  => '#{basedir}/file',
118           content => '1',
119         }
120
121         concat::fragment { '2':
122           target  => '#{basedir}/file',
123           content => '2',
124         }
125       EOS
126
127       it 'applies the manifest twice with no stderr' do
128         apply_manifest(pp, :catch_failures => true)
129         apply_manifest(pp, :catch_changes => true)
130       end
131
132       # XXX specinfra doesn't support be_linked_to on AIX
133       describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX" or fact("osfamily") == "windows") do
134         it { should be_linked_to "#{basedir}/dangling" }
135       end
136
137       describe file("#{basedir}/dangling") do
138         # XXX serverspec does not have a matcher for 'exists'
139         it { should_not be_file }
140         it { should_not be_directory }
141       end
142     end
143
144     context 'should succeed' do
145       # XXX the core puppet file type will replace a symlink with a plain file
146       # when using ensure => present and source => ... but it will not when using
147       # ensure => present and content => ...; this is somewhat confusing behavior
148       before(:all) do
149         pp = <<-EOS
150           file { '#{basedir}':
151             ensure => directory,
152           }
153           file { '#{basedir}/file':
154             ensure => link,
155             target => '#{basedir}/dangling',
156           }
157         EOS
158         apply_manifest(pp)
159       end
160
161       pp = <<-EOS
162         concat { '#{basedir}/file':
163           replace => true,
164         }
165
166         concat::fragment { '1':
167           target  => '#{basedir}/file',
168           content => '1',
169         }
170
171         concat::fragment { '2':
172           target  => '#{basedir}/file',
173           content => '2',
174         }
175       EOS
176
177       it 'applies the manifest twice with no stderr' do
178         apply_manifest(pp, :catch_failures => true)
179         apply_manifest(pp, :catch_changes => true)
180       end
181
182       describe file("#{basedir}/file") do
183         it { should be_file }
184         its(:content) {
185           should match '1'
186           should match '2'
187         }
188       end
189     end
190   end # symlink
191
192   context 'directory' do
193     context 'should not succeed' do
194       before(:all) do
195         pp = <<-EOS
196           file { '#{basedir}':
197             ensure => directory,
198           }
199           file { '#{basedir}/file':
200             ensure => directory,
201           }
202         EOS
203         apply_manifest(pp)
204       end
205       pp = <<-EOS
206         concat { '#{basedir}/file': }
207
208         concat::fragment { '1':
209           target  => '#{basedir}/file',
210           content => '1',
211         }
212
213         concat::fragment { '2':
214           target  => '#{basedir}/file',
215           content => '2',
216         }
217       EOS
218
219       it 'applies the manifest twice with stderr for changing to file' do
220         expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from '?directory'? to '?file'? failed/)
221         expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from '?directory'? to '?file'? failed/)
222       end
223
224       describe file("#{basedir}/file") do
225         it { should be_directory }
226       end
227     end
228
229     # XXX 
230     # when there are no fragments, and the replace param will only replace
231     # files and symlinks, not directories.  The semantics either need to be
232     # changed, extended, or a new param introduced to control directory
233     # replacement.
234     context 'should succeed', :pending => 'not yet implemented' do
235       pp = <<-EOS
236         concat { '#{basedir}/file':
237         }
238
239         concat::fragment { '1':
240           target  => '#{basedir}/file',
241           content => '1',
242         }
243
244         concat::fragment { '2':
245           target  => '#{basedir}/file',
246           content => '2',
247         }
248       EOS
249
250       it 'applies the manifest twice with no stderr' do
251         apply_manifest(pp, :catch_failures => true)
252         apply_manifest(pp, :catch_changes => true)
253       end
254
255       describe file("#{basedir}/file") do
256         it { should be_file }
257         its(:content) { should match '1' }
258       end
259     end
260   end # directory
261 end