diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 21:08:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 21:08:19 +0300 |
commit | a8de96bff51846e160b76506dc0ca0fe6f767f64 (patch) | |
tree | 1036f1ca75aba492eaaa3439c84a3109b4684896 /spec/lib/gitlab/import_export | |
parent | afe2b984524ae4b0c8a0636db7ec5b2c452f0734 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/import_export')
4 files changed, 197 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 78e80576aef..bbb61b4c356 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -467,6 +467,7 @@ project: - resource_groups - autoclose_referenced_issues - status_page_setting +- requirements award_emoji: - awardable - user diff --git a/spec/lib/gitlab/import_export/error_spec.rb b/spec/lib/gitlab/import_export/error_spec.rb new file mode 100644 index 00000000000..067f7049097 --- /dev/null +++ b/spec/lib/gitlab/import_export/error_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::ImportExport::Error do + describe '.permission_error' do + subject(:error) do + described_class.permission_error(user, importable) + end + + let(:user) { build(:user, id: 1) } + + context 'when supplied a project' do + let(:importable) { build(:project, id: 1, name: 'project1') } + + it 'returns an error with the correct message' do + expect(error.message) + .to eq 'User with ID: 1 does not have required permissions for Project: project1 with ID: 1' + end + end + + context 'when supplied a group' do + let(:importable) { build(:group, id: 1, name: 'group1') } + + it 'returns an error with the correct message' do + expect(error.message) + .to eq 'User with ID: 1 does not have required permissions for Group: group1 with ID: 1' + end + end + end +end diff --git a/spec/lib/gitlab/import_export/project/export_task_spec.rb b/spec/lib/gitlab/import_export/project/export_task_spec.rb new file mode 100644 index 00000000000..cf11a1df33c --- /dev/null +++ b/spec/lib/gitlab/import_export/project/export_task_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'rake_helper' + +describe Gitlab::ImportExport::Project::ExportTask do + let(:username) { 'root' } + let(:namespace_path) { username } + let!(:user) { create(:user, username: username) } + let(:measurement_enabled) { false } + let(:file_path) { 'spec/fixtures/gitlab/import_export/test_project_export.tar.gz' } + let(:project) { create(:project, creator: user, namespace: user.namespace) } + let(:project_name) { project.name } + + let(:task_params) do + { + username: username, + namespace_path: namespace_path, + project_path: project_name, + file_path: file_path, + measurement_enabled: measurement_enabled + } + end + + subject { described_class.new(task_params).export } + + context 'when project is found' do + let(:project) { create(:project, creator: user, namespace: user.namespace) } + + around do |example| + example.run + ensure + File.delete(file_path) + end + + it 'performs project export successfully' do + expect { subject }.to output(/Done!/).to_stdout + + expect(subject).to eq(true) + + expect(File).to exist(file_path) + end + + it_behaves_like 'measurable' + end + + context 'when project is not found' do + let(:project_name) { 'invalid project name' } + + it 'logs an error' do + expect { subject }.to output(/Project with path: #{project_name} was not found. Please provide correct project path/).to_stdout + end + + it 'returns false' do + expect(subject).to eq(false) + end + end + + context 'when file path is invalid' do + let(:file_path) { '/invalid_file_path/test_project_export.tar.gz' } + + it 'logs an error' do + expect { subject }.to output(/Invalid file path: #{file_path}. Please provide correct file path/ ).to_stdout + end + + it 'returns false' do + expect(subject).to eq(false) + end + end +end diff --git a/spec/lib/gitlab/import_export/project/import_task_spec.rb b/spec/lib/gitlab/import_export/project/import_task_spec.rb new file mode 100644 index 00000000000..f7b9cbaa095 --- /dev/null +++ b/spec/lib/gitlab/import_export/project/import_task_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require 'rake_helper' + +describe Gitlab::ImportExport::Project::ImportTask do + let(:username) { 'root' } + let(:namespace_path) { username } + let!(:user) { create(:user, username: username) } + let(:measurement_enabled) { false } + let(:project) { Project.find_by_full_path("#{namespace_path}/#{project_name}") } + let(:import_task) { described_class.new(task_params) } + let(:task_params) do + { + username: username, + namespace_path: namespace_path, + project_path: project_name, + file_path: file_path, + measurement_enabled: measurement_enabled + } + end + + before do + allow(Settings.uploads.object_store).to receive(:[]=).and_call_original + end + + around do |example| + old_direct_upload_setting = Settings.uploads.object_store['direct_upload'] + old_background_upload_setting = Settings.uploads.object_store['background_upload'] + + Settings.uploads.object_store['direct_upload'] = true + Settings.uploads.object_store['background_upload'] = true + + example.run + + Settings.uploads.object_store['direct_upload'] = old_direct_upload_setting + Settings.uploads.object_store['background_upload'] = old_background_upload_setting + end + + subject { import_task.import } + + context 'when project import is valid' do + let(:project_name) { 'import_rake_test_project' } + let(:file_path) { 'spec/fixtures/gitlab/import_export/lightweight_project_export.tar.gz' } + + it 'performs project import successfully' do + expect { subject }.to output(/Done!/).to_stdout + expect { subject }.not_to raise_error + expect(subject).to eq(true) + + expect(project.merge_requests.count).to be > 0 + expect(project.issues.count).to be > 0 + expect(project.milestones.count).to be > 0 + expect(project.import_state.status).to eq('finished') + end + + it 'disables direct & background upload only during project creation' do + expect_next_instance_of(Projects::GitlabProjectsImportService) do |service| + expect(service).to receive(:execute).and_wrap_original do |m| + expect(Settings.uploads.object_store['background_upload']).to eq(false) + expect(Settings.uploads.object_store['direct_upload']).to eq(false) + + m.call + end + end + + expect(import_task).to receive(:execute_sidekiq_job).and_wrap_original do |m| + expect(Settings.uploads.object_store['background_upload']).to eq(true) + expect(Settings.uploads.object_store['direct_upload']).to eq(true) + expect(Settings.uploads.object_store).not_to receive(:[]=).with('backgroud_upload', false) + expect(Settings.uploads.object_store).not_to receive(:[]=).with('direct_upload', false) + + m.call + end + + subject + end + + it_behaves_like 'measurable' + end + + context 'when project import is invalid' do + let(:project_name) { 'import_rake_invalid_test_project' } + let(:file_path) { 'spec/fixtures/gitlab/import_export/corrupted_project_export.tar.gz' } + let(:not_imported_message) { /Total number of not imported relations: 1/ } + + it 'performs project import successfully' do + expect { subject }.to output(not_imported_message).to_stdout + expect { subject }.not_to raise_error + expect(subject).to eq(true) + + expect(project.merge_requests).to be_empty + expect(project.import_state.last_error).to be_nil + expect(project.import_state.status).to eq('finished') + end + end +end |