Skip to content

Commit 7c296e8

Browse files
committed
Add explicit tests for temp_dir stuff
1 parent 2c6d7e0 commit 7c296e8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/octocatalog-diff/util/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.temp_dir(prefix = 'ocd-', basedir = ENV['OCTOCATALOG_DIFF_TEMPDIR'])
7070
the_dir = Dir.mktmpdir(prefix)
7171
at_exit do
7272
begin
73-
FileUtils.remove_entry_secure the_dir
73+
FileUtils.remove_entry_secure(the_dir) if File.directory?(the_dir)
7474
rescue Errno::ENOENT # rubocop:disable Lint/HandleExceptions
7575
# OK if the directory doesn't exist since we're trying to remove it anyway
7676
end

spec/octocatalog-diff/tests/util/util_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,23 @@
8484
expect(result).to eq(obj)
8585
end
8686
end
87+
88+
describe '#temp_dir' do
89+
after(:all) do
90+
ENV.delete('OCTOCATALOG_DIFF_TEMPDIR')
91+
end
92+
93+
it 'should create a temporary directory when no base directory is specified' do
94+
ENV.delete('OCTOCATALOG_DIFF_TEMPDIR')
95+
expect(Dir).to receive(:mktmpdir).with('ocd-').and_return('adsdasdfasdf')
96+
expect(described_class.temp_dir).to eq('adsdasdfasdf')
97+
end
98+
99+
it 'should create a temporary directory within OCTOCATALOG_DIFF_TEMPDIR when specified' do
100+
ENV['OCTOCATALOG_DIFF_TEMPDIR'] = '/var/tmp/asdfasdfasdf'
101+
expect(File).to receive(:'directory?').with('/var/tmp/asdfasdfasdf').and_return(true)
102+
expect(Dir).to receive(:mktmpdir).with('ocd-', '/var/tmp/asdfasdfasdf').and_return('/var/tmp/asdfasdfasdf/qwertyuiop')
103+
expect(described_class.temp_dir).to eq('/var/tmp/asdfasdfasdf/qwertyuiop')
104+
end
105+
end
87106
end

0 commit comments

Comments
 (0)