Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/puppet/provider/file_line/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def lines
rescue TypeError => _e
# Ruby 1.8 doesn't support open_args
@lines ||= File.readlines(resource[:path])
rescue Errno::ENOENT => _e
raise _e unless resource.noop?
Comment thread
silug marked this conversation as resolved.
Outdated
@lines ||= []
end

def new_after_regex
Expand Down
54 changes: 54 additions & 0 deletions spec/acceptance/file_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
ensure => present,
content => 'a wild test file has appeared!',
}
file { '#{test_file}.does_not_exist':
ensure => absent,
}
MANIFEST
apply_manifest(pp_test_file)
end
Expand Down Expand Up @@ -97,4 +100,55 @@
end
end
end

context 'when file does not exist' do
context 'with ensure => present' do
let(:pp) do
<<~MANIFEST
file_line { 'test_absent_file':
ensure => present,
path => '#{test_file}.does_not_exist',
line => 'this file does not exist',
}
MANIFEST
end

it 'fails to apply manifest' do
apply_manifest(pp, expect_failures: true)
end
end

context 'with ensure => present and noop => true' do
let(:pp) do
<<~MANIFEST
file_line { 'test_absent_file':
ensure => present,
path => '#{test_file}.does_not_exist',
line => 'this file does not exist',
noop => true,
}
MANIFEST
end

it 'would apply manifest' do
apply_manifest(pp, catch_failures: true)
end
end

context 'with ensure => present, in noop mode' do
let(:pp) do
<<~MANIFEST
file_line { 'test_absent_file':
ensure => present,
path => '#{test_file}.does_not_exist',
line => 'this file does not exist',
}
MANIFEST
end

it 'would apply manifest' do
apply_manifest(pp, catch_failures: true, noop: true)
end
end
end
end