Skip to content

Commit

Permalink
Merge pull request #3287 from jay7x/file_delete
Browse files Browse the repository at this point in the history
(GH-3286) Add `file::delete()` function
  • Loading branch information
donoghuc authored Apr 16, 2024
2 parents 2a58ca1 + b4a2a01 commit f758ac2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bolt-modules/file/lib/puppet/functions/file/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# Delete a file on localhost using ruby's `File.delete`. This will only delete
# files on the machine you run Bolt on.
Puppet::Functions.create_function(:'file::delete') do
# @param filename Absolute path.
# @example Delete a file from disk
# file::delete('C:/Users/me/report')
dispatch :delete do
required_param 'String[1]', :filename
return_type 'Undef'
end

def delete(filename)
# Send Analytics Report
Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)

File.delete(filename)
nil
end
end
15 changes: 15 additions & 0 deletions bolt-modules/file/spec/functions/file/delete_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'
require 'tempfile'

describe 'file::delete' do
it {
Dir.mktmpdir do |dir|
file = File.join(dir, 'file_delete')
File.write(file, 'file_delete_contents')
is_expected.to run.with_params(file)
expect(File.exist?(file)).to eq(false)
end
}
end

0 comments on commit f758ac2

Please sign in to comment.