File tree 2 files changed +36
-0
lines changed
lib/puppet/functions/file
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ # Delete a file on localhost using ruby's `File.delete`. This will only delete
4
+ # files on the machine you run Bolt on.
5
+ Puppet ::Functions . create_function ( :'file::delete' ) do
6
+ # @param filename Absolute path.
7
+ # @example Delete a file from disk
8
+ # file::delete('C:/Users/me/report')
9
+ dispatch :delete do
10
+ required_param 'String[1]' , :filename
11
+ return_type 'Undef'
12
+ end
13
+
14
+ def delete ( filename )
15
+ # Send Analytics Report
16
+ Puppet . lookup ( :bolt_executor ) { } &.report_function_call ( self . class . name )
17
+
18
+ File . delete ( filename )
19
+ nil
20
+ end
21
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'tempfile'
5
+
6
+ describe 'file::delete' do
7
+ it {
8
+ Dir . mktmpdir do |dir |
9
+ file = File . join ( dir , 'file_delete' )
10
+ File . write ( file , 'file_delete_contents' )
11
+ is_expected . to run . with_params ( file )
12
+ expect ( File . exist? ( file ) ) . to eq ( false )
13
+ end
14
+ }
15
+ end
You can’t perform that action at this time.
0 commit comments