1 require 'spec_helper_acceptance'
3 describe 'replacement of' do
5 @basedir = setup_test_directory
11 concat { '#{@basedir}/file':
15 concat::fragment { '1':
16 target => '#{@basedir}/file',
20 concat::fragment { '2':
21 target => '#{@basedir}/file',
25 concat { '#{@basedir}/file2':
29 concat::fragment { 'file2_1':
30 target => '#{@basedir}/file2',
34 concat::fragment { 'file2_2':
35 target => '#{@basedir}/file2',
41 it 'when file should not succeed' do
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'
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'
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
65 file { '#{@basedir}/file':
67 target => '#{@basedir}/dangling',
75 concat { '#{@basedir}/file':
79 concat::fragment { '1':
80 target => '#{@basedir}/file',
84 concat::fragment { '2':
85 target => '#{@basedir}/file',
89 concat { '#{@basedir}/file2':
93 concat::fragment { 'file2_1':
94 target => '#{@basedir}/file2',
98 concat::fragment { 'file2_2':
99 target => '#{@basedir}/file2',
105 it 'when symlink should not succeed' do
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
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'
118 describe 'when directory should not succeed' do
121 file { '#{@basedir}':
124 file { '#{@basedir}/file':
132 concat { '#{@basedir}/file': }
134 concat::fragment { '1':
135 target => '#{@basedir}/file',
139 concat::fragment { '2':
140 target => '#{@basedir}/file',
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
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
158 describe 'when directory should succeed', pending: 'not yet implemented' do
161 concat { '#{@basedir}/file':
164 concat::fragment { '1':
165 target => '#{@basedir}/file',
169 concat::fragment { '2':
170 target => '#{@basedir}/file',
176 it 'applies the manifest twice with no stderr' do
178 expect(file("#{@basedir}/file")).to be_file
179 expect(file("#{@basedir}/file").content).to match '1'