2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-02 18:00:53 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
describe Gitlab::ImportExport::Shared do
|
|
|
|
let(:project) { build(:project) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2019-02-02 18:00:53 +05:30
|
|
|
subject { project.import_export_shared }
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'with a repository on disk' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:base_path) { %(/tmp/gitlab_exports/#{project.disk_path}/) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
describe '#archive_path' do
|
|
|
|
it 'uses a random hash to avoid conflicts' do
|
|
|
|
expect(subject.archive_path).to match(/#{base_path}\h{32}/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'memoizes the path' do
|
|
|
|
path = subject.archive_path
|
|
|
|
|
|
|
|
2.times { expect(subject.archive_path).to eq(path) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#export_path' do
|
|
|
|
it 'uses a random hash relative to project path' do
|
|
|
|
expect(subject.export_path).to match(/#{base_path}\h{32}\/\h{32}/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'memoizes the path' do
|
|
|
|
path = subject.export_path
|
|
|
|
|
|
|
|
2.times { expect(subject.export_path).to eq(path) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 18:00:53 +05:30
|
|
|
describe '#error' do
|
|
|
|
let(:error) { StandardError.new('Error importing into /my/folder Permission denied @ unlink_internal - /var/opt/gitlab/gitlab-rails/shared/a/b/c/uploads/file') }
|
|
|
|
|
|
|
|
it 'filters any full paths' do
|
|
|
|
subject.error(error)
|
|
|
|
|
|
|
|
expect(subject.errors).to eq(['Error importing into [FILTERED] Permission denied @ unlink_internal - [FILTERED]'])
|
|
|
|
end
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
it 'updates the import JID' do
|
|
|
|
import_state = create(:import_state, project: project, jid: 'jid-test')
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(Gitlab::ErrorTracking)
|
|
|
|
.to receive(:track_exception)
|
|
|
|
.with(error, hash_including(import_jid: import_state.jid))
|
2019-02-02 18:00:53 +05:30
|
|
|
|
|
|
|
subject.error(error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|