Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / fragment_replace_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'replacement of' do
4   before(:all) do
5     @basedir = setup_test_directory
6   end
7
8   describe 'file' do
9     let(:pp) do
10       <<-MANIFEST
11         concat { '#{@basedir}/file':
12           replace => false,
13         }
14
15         concat::fragment { '1':
16           target  => '#{@basedir}/file',
17           content => '1',
18         }
19
20         concat::fragment { '2':
21           target  => '#{@basedir}/file',
22           content => '2',
23         }
24
25         concat { '#{@basedir}/file2':
26           replace => true,
27         }
28
29         concat::fragment { 'file2_1':
30           target  => '#{@basedir}/file2',
31           content => '1',
32         }
33
34         concat::fragment { 'file2_2':
35           target  => '#{@basedir}/file2',
36           content => '2',
37         }
38       MANIFEST
39     end
40
41     it 'when file should not succeed' do
42       idempotent_apply(pp)
43       expect(file("#{@basedir}/file")).to be_file
44       expect(file("#{@basedir}/file").content).to match 'file exists'
45       expect(file("#{@basedir}/file").content).not_to match '1'
46       expect(file("#{@basedir}/file").content).not_to match '2'
47     end
48     it 'when file should succeed' do
49       expect(file("#{@basedir}/file2")).to be_file
50       expect(file("#{@basedir}/file2").content).not_to match 'file exists'
51       expect(file("#{@basedir}/file2").content).to match '1'
52       expect(file("#{@basedir}/file2").content).to match '2'
53     end
54   end
55
56   describe 'symlink', unless: (os[:family] == 'windows') do
57     # XXX the core puppet file type will replace a symlink with a plain file
58     # when using ensure => present and source => ... but it will not when using
59     # ensure => present and content => ...; this is somewhat confusing behavior
60     before(:all) do
61       pp = <<-MANIFEST
62           file { '#{@basedir}':
63             ensure => directory,
64           }
65           file { '#{@basedir}/file':
66             ensure => link,
67             target => '#{@basedir}/dangling',
68           }
69         MANIFEST
70       apply_manifest(pp)
71     end
72
73     let(:pp) do
74       <<-MANIFEST
75         concat { '#{@basedir}/file':
76           replace => false,
77         }
78
79         concat::fragment { '1':
80           target  => '#{@basedir}/file',
81           content => '1',
82         }
83
84         concat::fragment { '2':
85           target  => '#{@basedir}/file',
86           content => '2',
87         }
88
89         concat { '#{@basedir}/file2':
90           replace => true,
91         }
92
93         concat::fragment { 'file2_1':
94           target  => '#{@basedir}/file2',
95           content => '1',
96         }
97
98         concat::fragment { 'file2_2':
99           target  => '#{@basedir}/file2',
100           content => '2',
101         }
102       MANIFEST
103     end
104
105     it 'when symlink should not succeed' do
106       idempotent_apply(pp)
107       expect(file("#{@basedir}/file")).to be_linked_to "#{@basedir}/dangling" unless os[:family] == 'aix' || os[:family] == 'windows'
108       expect(file("#{@basedir}/dangling")).not_to be_file
109       expect(file("#{@basedir}/dangling")).not_to be_directory
110     end
111     it 'when symlink should succeed' do
112       expect(file("#{@basedir}/file2")).to be_file
113       expect(file("#{@basedir}/file2").content).to match '1'
114       expect(file("#{@basedir}/file2").content).to match '2'
115     end
116   end
117
118   describe 'when directory should not succeed' do
119     before(:all) do
120       pp = <<-MANIFEST
121           file { '#{@basedir}':
122             ensure => directory,
123           }
124           file { '#{@basedir}/file':
125             ensure => directory,
126           }
127         MANIFEST
128       apply_manifest(pp)
129     end
130     let(:pp) do
131       <<-MANIFEST
132         concat { '#{@basedir}/file': }
133
134         concat::fragment { '1':
135           target  => '#{@basedir}/file',
136           content => '1',
137         }
138
139         concat::fragment { '2':
140           target  => '#{@basedir}/file',
141           content => '2',
142         }
143       MANIFEST
144     end
145
146     it 'applies the manifest twice with stderr' do
147       expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{change from '?directory'? to '?file'? failed})
148       expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{change from '?directory'? to '?file'? failed})
149       expect(file("#{@basedir}/file")).to be_directory
150     end
151   end
152
153   # XXX
154   # when there are no fragments, and the replace param will only replace
155   # files and symlinks, not directories.  The semantics either need to be
156   # changed, extended, or a new param introduced to control directory
157   # replacement.
158   describe 'when directory should succeed', pending: 'not yet implemented' do
159     let(:pp) do
160       <<-MANIFEST
161         concat { '#{@basedir}/file':
162         }
163
164         concat::fragment { '1':
165           target  => '#{@basedir}/file',
166           content => '1',
167         }
168
169         concat::fragment { '2':
170           target  => '#{@basedir}/file',
171           content => '2',
172         }
173       MANIFEST
174     end
175
176     it 'applies the manifest twice with no stderr' do
177       idempotent_apply(pp)
178       expect(file("#{@basedir}/file")).to be_file
179       expect(file("#{@basedir}/file").content).to match '1'
180     end
181   end
182 end