File tree Expand file tree Collapse file tree
lib/berkeley_library/sftp_handler/downloader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,11 +41,6 @@ def ssh_options
4141 end
4242 end
4343
44- def assert_file_not_processed! ( processed_path )
45- raise "File was already processed: #{ processed_path } " \
46- if Pathname . new ( processed_path ) . exist?
47- end
48-
4944 def assert_not_exists! ( local_path )
5045 raise "Local file already exists: #{ local_path } " \
5146 if Pathname . new ( local_path ) . exist?
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def download!(filename: nil, local_dir: '/opt/app/data')
1515 filename ||= default_filename
1616 remote_path = Pathname . new ( filename )
1717 local_path = Pathname . new ( local_dir ) + filename
18- assert_file_not_processed! local_path + '.old'
18+ assert_file_not_processed! local_path
1919 assert_not_exists! local_path
2020
2121 connect do |sftp |
@@ -25,6 +25,11 @@ def download!(filename: nil, local_dir: '/opt/app/data')
2525 end
2626 end
2727
28+ def assert_file_not_processed! ( filepath )
29+ raise "File was already processed: #{ filepath } " \
30+ if Pathname . glob ( "#{ filepath } *.old" ) . any?
31+ end
32+
2833 def default_host
2934 'ncc-1701.lbl.gov'
3035 end
Original file line number Diff line number Diff line change 99 end
1010 end
1111
12- describe '#assert_file_not_processed!' do
13- it 'proceeds if processed file is absent' do
14- expect { subject . assert_file_not_processed! '/path/to/non-existent-file' } . not_to raise_error
15- end
16-
17- it 'raises if processed file exists' do
18- Tempfile . open do |f |
19- expect { subject . assert_file_not_processed! f . path } . to raise_error RuntimeError
20- end
21- end
22- end
23-
2412 describe '#assert_not_exists!' do
2513 it 'proceeds if file is absent' do
2614 expect { subject . assert_not_exists! '/path/to/non-existent-file' } . not_to raise_error
Original file line number Diff line number Diff line change 11require 'berkeley_library/sftp_handler/downloader/lbnl'
22require 'net/sftp'
33require 'spec_helper'
4+ require 'tempfile'
45
56describe BerkeleyLibrary ::SftpHandler ::Downloader ::Lbnl do
67 its ( :default_host ) { is_expected . to eq 'ncc-1701.lbl.gov' }
5556 end
5657 end
5758
59+ describe '#assert_file_not_processed!' do
60+ it 'proceeds if processed file is absent' do
61+ expect { subject . assert_file_not_processed! ( '/path/to/non-existent-file' ) } . not_to raise_error
62+ end
63+
64+ it 'raises if processed file exists' do
65+ f = Tempfile . new ( [ 'temp_file38348' , '.old' ] )
66+ expect { subject . assert_file_not_processed! f . path . gsub ( '.old' , '' ) } . to raise_error RuntimeError
67+ end
68+ end
69+
5870 describe '#default_filename' do
5971 context 'on Sunday May 29, 2022' do
6072 its ( :default_filename ) do
You can’t perform that action at this time.
0 commit comments