diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-10 23:42:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-10 23:43:16 +0300 |
commit | b55e13ec164336d1e5d5bbdbca939edcc31d557f (patch) | |
tree | b3283adcd5aa0cd6ac55afc75793189e7507e4ae /spec/lib/gitlab/import_export/command_line_util_spec.rb | |
parent | ceaba594d07563402ac901c958b9a6e27c4964dc (diff) |
Add latest changes from gitlab-org/security/gitlab@14-6-stable-ee
Diffstat (limited to 'spec/lib/gitlab/import_export/command_line_util_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/command_line_util_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb index 59c4e1083ae..31512259bb1 100644 --- a/spec/lib/gitlab/import_export/command_line_util_spec.rb +++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb @@ -101,4 +101,39 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do end end end + + describe '#untar_xf' do + let(:archive_dir) { Dir.mktmpdir } + + after do + FileUtils.remove_entry(archive_dir) + end + + it 'extracts archive without decompression' do + filename = 'archive.tar.gz' + archive_file = File.join(archive_dir, 'archive.tar') + + FileUtils.copy_file(archive, File.join(archive_dir, filename)) + subject.gunzip(dir: archive_dir, filename: filename) + + result = subject.untar_xf(archive: archive_file, dir: archive_dir) + + expect(result).to eq(true) + expect(File.exist?(archive_file)).to eq(true) + expect(File.exist?(File.join(archive_dir, 'project.json'))).to eq(true) + expect(Dir.exist?(File.join(archive_dir, 'uploads'))).to eq(true) + end + + context 'when something goes wrong' do + it 'raises an error' do + expect(Gitlab::Popen).to receive(:popen).and_return(['Error', 1]) + + klass = Class.new do + include Gitlab::ImportExport::CommandLineUtil + end.new + + expect { klass.untar_xf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'System call failed') + end + end + end end |