2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
require 'spec_helper'
|
2016-11-03 12:29:30 +05:30
|
|
|
include ImportExport::CommonUtil
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Gitlab::ImportExport::ProjectTreeRestorer do
|
2019-12-26 22:10:19 +05:30
|
|
|
include ImportExport::CommonUtil
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:shared) { project.import_export_shared }
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe 'restore project tree' do
|
2017-08-17 22:00:37 +05:30
|
|
|
before(:context) do
|
2018-05-09 12:01:36 +05:30
|
|
|
# Using an admin for import, so we can check assignment of existing members
|
|
|
|
@user = create(:admin)
|
|
|
|
@existing_members = [
|
2020-03-13 15:44:24 +05:30
|
|
|
create(:user, email: 'bernard_willms@gitlabexample.com'),
|
|
|
|
create(:user, email: 'saul_will@gitlabexample.com')
|
2018-05-09 12:01:36 +05:30
|
|
|
]
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
RSpec::Mocks.with_temporary_scope do
|
2019-02-02 18:00:53 +05:30
|
|
|
@project = create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project')
|
2018-03-27 19:54:05 +05:30
|
|
|
@shared = @project.import_export_shared
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
setup_import_export_config('complex')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
allow_any_instance_of(Repository).to receive(:fetch_source_branch!).and_return(true)
|
2018-03-17 18:26:18 +05:30
|
|
|
allow_any_instance_of(Gitlab::Git::Repository).to receive(:branch_exists?).and_return(false)
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::Git::Repository).to receive(:create_branch).with('feature', 'DCBA')
|
|
|
|
allow_any_instance_of(Gitlab::Git::Repository).to receive(:create_branch)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
project_tree_restorer = described_class.new(user: @user, shared: @shared, project: @project)
|
2018-06-03 19:52:53 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@restored_project_json = project_tree_restorer.restore
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'JSON' do
|
|
|
|
it 'restores models based on JSON' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(@restored_project_json).to be_truthy
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
it 'restore correct project features' do
|
|
|
|
project = Project.find_by_path('project')
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(project.project_feature.issues_access_level).to eq(ProjectFeature::PRIVATE)
|
|
|
|
expect(project.project_feature.builds_access_level).to eq(ProjectFeature::PRIVATE)
|
|
|
|
expect(project.project_feature.snippets_access_level).to eq(ProjectFeature::PRIVATE)
|
|
|
|
expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::PRIVATE)
|
|
|
|
expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::PRIVATE)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'has the project description' do
|
|
|
|
expect(Project.find_by_path('project').description).to eq('Nisi et repellendus ut enim quo accusamus vel magnam.')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has the same label associated to two issues' do
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(ProjectLabel.find_by_title('test2').issues.count).to eq(2)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has milestones associated to two separate issues' do
|
|
|
|
expect(Milestone.find_by_description('test milestone').issues.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2019-06-05 12:25:43 +05:30
|
|
|
context 'when importing a project with cached_markdown_version and note_html' do
|
|
|
|
context 'for an Issue' do
|
|
|
|
it 'does not import note_html' do
|
|
|
|
note_content = 'Quo reprehenderit aliquam qui dicta impedit cupiditate eligendi'
|
|
|
|
issue_note = Issue.find_by(description: 'Aliquam enim illo et possimus.').notes.select { |n| n.note.match(/#{note_content}/)}.first
|
|
|
|
|
|
|
|
expect(issue_note.note_html).to match(/#{note_content}/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a Merge Request' do
|
|
|
|
it 'does not import note_html' do
|
|
|
|
note_content = 'Sit voluptatibus eveniet architecto quidem'
|
|
|
|
merge_request_note = MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{note_content}/)}.first
|
|
|
|
|
|
|
|
expect(merge_request_note.note_html).to match(/#{note_content}/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
it 'creates a valid pipeline note' do
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(Ci::Pipeline.find_by_sha('sha-notes').notes).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pipeline has the correct user ID' do
|
|
|
|
expect(Ci::Pipeline.find_by_sha('sha-notes').user_id).to eq(@user.id)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
it 'restores pipelines with missing ref' do
|
|
|
|
expect(Ci::Pipeline.where(ref: nil)).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'restores pipeline for merge request' do
|
|
|
|
pipeline = Ci::Pipeline.find_by_sha('048721d90c449b244b7b4c53a9186b04330174ec')
|
|
|
|
|
|
|
|
expect(pipeline).to be_valid
|
|
|
|
expect(pipeline.tag).to be_falsey
|
|
|
|
expect(pipeline.source).to eq('merge_request_event')
|
|
|
|
expect(pipeline.merge_request.id).to be > 0
|
|
|
|
expect(pipeline.merge_request.target_branch).to eq('feature')
|
|
|
|
expect(pipeline.merge_request.source_branch).to eq('feature_conflict')
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
it 'preserves updated_at on issues' do
|
|
|
|
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first
|
|
|
|
|
|
|
|
expect(issue.reload.updated_at.to_s).to eq('2016-06-14 15:02:47 UTC')
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'has multiple issue assignees' do
|
|
|
|
expect(Issue.find_by(title: 'Voluptatem').assignees).to contain_exactly(@user, *@existing_members)
|
|
|
|
expect(Issue.find_by(title: 'Issue without assignees').assignees).to be_empty
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'restores timelogs for issues' do
|
|
|
|
timelog = Issue.find_by(title: 'issue_with_timelogs').timelogs.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(timelog.time_spent).to eq(72000)
|
|
|
|
expect(timelog.spent_at).to eq("2019-12-27T00:00:00.000Z")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
it 'contains the merge access levels on a protected branch' do
|
|
|
|
expect(ProtectedBranch.first.merge_access_levels).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the push access levels on a protected branch' do
|
|
|
|
expect(ProtectedBranch.first.push_access_levels).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'contains the create access levels on a protected tag' do
|
|
|
|
expect(ProtectedTag.first.create_access_levels).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'restores issue resource label events' do
|
|
|
|
expect(Issue.find_by(title: 'Voluptatem').resource_label_events).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores merge requests resource label events' do
|
|
|
|
expect(MergeRequest.find_by(title: 'MR1').resource_label_events).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'restores suggestion' do
|
|
|
|
note = Note.find_by("note LIKE 'Saepe asperiores exercitationem non dignissimos laborum reiciendis et ipsum%'")
|
|
|
|
|
|
|
|
expect(note.suggestions.count).to eq(1)
|
|
|
|
expect(note.suggestions.first.from_content).to eq("Original line\n")
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'event at forth level of the tree' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:event) { Event.where(action: 6).first }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
it 'restores the event' do
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'has the action' do
|
|
|
|
expect(event.action).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
it 'event belongs to note, belongs to merge request, belongs to a project' do
|
|
|
|
expect(event.note.noteable.project).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'has the correct data for merge request diff files' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(MergeRequestDiffFile.where.not(diff: nil).count).to eq(55)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'has the correct data for merge request diff commits' do
|
|
|
|
expect(MergeRequestDiffCommit.count).to eq(77)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'has the correct data for merge request latest_merge_request_diff' do
|
|
|
|
MergeRequest.find_each do |merge_request|
|
|
|
|
expect(merge_request.latest_merge_request_diff_id).to eq(merge_request.merge_request_diffs.maximum(:id))
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has labels associated to label links, associated to issues' do
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(Label.first.label_links.first.target).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'has project labels' do
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(ProjectLabel.count).to eq(3)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no group labels' do
|
|
|
|
expect(GroupLabel.count).to eq(0)
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'has issue boards' do
|
|
|
|
expect(Project.find_by_path('project').boards.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has lists associated with the issue board' do
|
|
|
|
expect(Project.find_by_path('project').boards.find_by_name('TestBoardABC').lists.count).to eq(3)
|
|
|
|
end
|
|
|
|
|
2016-10-01 15:18:49 +05:30
|
|
|
it 'has a project feature' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(@project.project_feature).not_to be_nil
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'has custom attributes' do
|
|
|
|
expect(@project.custom_attributes.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'has badges' do
|
|
|
|
expect(@project.project_badges.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'has snippets' do
|
|
|
|
expect(@project.snippets.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has award emoji for a snippet' do
|
|
|
|
award_emoji = @project.snippets.first.award_emoji
|
|
|
|
|
|
|
|
expect(award_emoji.map(&:name)).to contain_exactly('thumbsup', 'coffee')
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'snippet has notes' do
|
|
|
|
expect(@project.snippets.first.notes.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'snippet has award emojis on notes' do
|
|
|
|
award_emoji = @project.snippets.first.notes.first.award_emoji.first
|
|
|
|
|
|
|
|
expect(award_emoji.name).to eq('thumbsup')
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'restores `ci_cd_settings` : `group_runners_enabled` setting' do
|
|
|
|
expect(@project.ci_cd_settings.group_runners_enabled?).to eq(false)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'restores `auto_devops`' do
|
|
|
|
expect(@project.auto_devops_enabled?).to eq(true)
|
|
|
|
expect(@project.auto_devops.deploy_strategy).to eq('continuous')
|
|
|
|
end
|
|
|
|
|
2016-10-01 15:18:49 +05:30
|
|
|
it 'restores the correct service' do
|
|
|
|
expect(CustomIssueTrackerService.first).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'restores zoom meetings' do
|
|
|
|
meetings = @project.issues.first.zoom_meetings
|
|
|
|
|
|
|
|
expect(meetings.count).to eq(1)
|
|
|
|
expect(meetings.first.url).to eq('https://zoom.us/j/123456789')
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'restores sentry issues' do
|
|
|
|
sentry_issue = @project.issues.first.sentry_issue
|
|
|
|
|
|
|
|
expect(sentry_issue.sentry_issue_identifier).to eq(1234567891)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'has award emoji for an issue' do
|
|
|
|
award_emoji = @project.issues.first.award_emoji.first
|
|
|
|
|
|
|
|
expect(award_emoji.name).to eq('musical_keyboard')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has award emoji for a note in an issue' do
|
|
|
|
award_emoji = @project.issues.first.notes.first.award_emoji.first
|
|
|
|
|
|
|
|
expect(award_emoji.name).to eq('clapper')
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'restores container_expiration_policy' do
|
|
|
|
policy = Project.find_by_path('project').container_expiration_policy
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(policy).to be_an_instance_of(ContainerExpirationPolicy)
|
|
|
|
expect(policy).to be_persisted
|
|
|
|
expect(policy.cadence).to eq('3month')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'restores error_tracking_setting' do
|
|
|
|
setting = @project.error_tracking_setting
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(setting.api_url).to eq("https://gitlab.example.com/api/0/projects/sentry-org/sentry-project")
|
|
|
|
expect(setting.project_name).to eq("Sentry Project")
|
|
|
|
expect(setting.organization_name).to eq("Sentry Org")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores external pull requests' do
|
|
|
|
external_pr = @project.external_pull_requests.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(external_pr.pull_request_iid).to eq(4)
|
|
|
|
expect(external_pr.source_branch).to eq("feature")
|
|
|
|
expect(external_pr.target_branch).to eq("master")
|
|
|
|
expect(external_pr.status).to eq("open")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores pipeline schedules' do
|
|
|
|
pipeline_schedule = @project.pipeline_schedules.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(pipeline_schedule.description).to eq('Schedule Description')
|
|
|
|
expect(pipeline_schedule.ref).to eq('master')
|
|
|
|
expect(pipeline_schedule.cron).to eq('0 4 * * 0')
|
|
|
|
expect(pipeline_schedule.cron_timezone).to eq('UTC')
|
|
|
|
expect(pipeline_schedule.active).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores releases with links' do
|
|
|
|
release = @project.releases.last
|
|
|
|
link = release.links.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(release.tag).to eq('release-1.1')
|
|
|
|
expect(release.description).to eq('Some release notes')
|
|
|
|
expect(release.name).to eq('release-1.1')
|
|
|
|
expect(release.sha).to eq('901de3a8bd5573f4a049b1457d28bc1592ba6bf9')
|
|
|
|
expect(release.released_at).to eq('2019-12-26T10:17:14.615Z')
|
|
|
|
|
|
|
|
expect(link.url).to eq('http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download')
|
|
|
|
expect(link.name).to eq('release-1.1.dmg')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'Merge requests' do
|
|
|
|
it 'always has the new project as a target' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(MergeRequest.find_by_title('MR1').target_project).to eq(@project)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the same source project as originally if source/target are the same' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(MergeRequest.find_by_title('MR1').source_project).to eq(@project)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the new project as target if source/target differ' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(MergeRequest.find_by_title('MR2').target_project).to eq(@project)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no source if source/target differ' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(MergeRequest.find_by_title('MR2').source_project_id).to be_nil
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'has award emoji' do
|
|
|
|
award_emoji = MergeRequest.find_by_title('MR1').award_emoji
|
|
|
|
|
|
|
|
expect(award_emoji.map(&:name)).to contain_exactly('thumbsup', 'drum')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'notes' do
|
|
|
|
it 'has award emoji' do
|
|
|
|
award_emoji = MergeRequest.find_by_title('MR1').notes.first.award_emoji.first
|
|
|
|
|
|
|
|
expect(award_emoji.name).to eq('tada')
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'tokens are regenerated' do
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'has new CI trigger tokens' do
|
|
|
|
expect(Ci::Trigger.where(token: %w[cdbfasdf44a5958c83654733449e585 33a66349b5ad01fc00174af87804e40]))
|
|
|
|
.to be_empty
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has a new CI build token' do
|
|
|
|
expect(Ci::Build.where(token: 'abcd')).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'has restored the correct number of records' do
|
|
|
|
it 'has the correct number of merge requests' do
|
|
|
|
expect(@project.merge_requests.size).to eq(9)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'only restores valid triggers' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(@project.triggers.size).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct number of pipelines and statuses' do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(@project.ci_pipelines.size).to eq(7)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
@project.ci_pipelines.order(:id).zip([2, 2, 2, 2, 2, 0, 0])
|
2017-08-17 22:00:37 +05:30
|
|
|
.each do |(pipeline, expected_status_size)|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(pipeline.statuses.size).to eq(expected_status_size)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when restoring hierarchy of pipeline, stages and jobs' do
|
|
|
|
it 'restores pipelines' do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(Ci::Pipeline.all.count).to be 7
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores pipeline stages' do
|
|
|
|
expect(Ci::Stage.all.count).to be 6
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly restores association between stage and a pipeline' do
|
|
|
|
expect(Ci::Stage.all).to all(have_attributes(pipeline_id: a_value > 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores statuses' do
|
|
|
|
expect(CommitStatus.all.count).to be 10
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly restores association between a stage and a job' do
|
|
|
|
expect(CommitStatus.all).to all(have_attributes(stage_id: a_value > 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly restores association between a pipeline and a job' do
|
|
|
|
expect(CommitStatus.all).to all(have_attributes(pipeline_id: a_value > 0))
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'restores a Hash for CommitStatus options' do
|
|
|
|
expect(CommitStatus.all.map(&:options).compact).to all(be_a(Hash))
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'restores external pull request for the restored pipeline' do
|
|
|
|
pipeline_with_external_pr = @project.ci_pipelines.order(:id).last
|
|
|
|
|
|
|
|
expect(pipeline_with_external_pr.external_pull_request).to be_persisted
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2018-06-03 19:52:53 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'restores group correctly' do |**results|
|
|
|
|
it 'has group label' do
|
|
|
|
expect(project.group.labels.size).to eq(results.fetch(:labels, 0))
|
|
|
|
expect(project.group.labels.where(type: "GroupLabel").where.not(project_id: nil).count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has group milestone' do
|
|
|
|
expect(project.group.milestones.size).to eq(results.fetch(:milestones, 0))
|
|
|
|
end
|
2019-02-02 18:00:53 +05:30
|
|
|
|
|
|
|
it 'has the correct visibility level' do
|
|
|
|
# INTERNAL in the `project.json`, group's is PRIVATE
|
|
|
|
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'project.json file access check' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project) { create(:project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:project_tree_restorer) do
|
|
|
|
described_class.new(user: user, shared: shared, project: project)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:restored_project_json) { project_tree_restorer.restore }
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'does not read a symlink' do
|
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
setup_symlink(tmpdir, 'project.json')
|
|
|
|
allow(shared).to receive(:export_path).and_call_original
|
|
|
|
|
|
|
|
expect(project_tree_restorer.restore).to eq(false)
|
|
|
|
expect(shared.errors).to include('Incorrect JSON format')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'Light JSON' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') }
|
|
|
|
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
|
|
|
|
let(:restored_project_json) { project_tree_restorer.restore }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'with a simple project' do
|
|
|
|
before do
|
2019-12-26 22:10:19 +05:30
|
|
|
setup_import_export_config('light')
|
|
|
|
expect(restored_project_json).to eq(true)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it_behaves_like 'restores project successfully',
|
2018-03-17 18:26:18 +05:30
|
|
|
issues: 1,
|
2019-09-30 21:07:59 +05:30
|
|
|
labels: 2,
|
2019-12-21 20:55:43 +05:30
|
|
|
label_with_priorities: 'A project label',
|
2018-03-17 18:26:18 +05:30
|
|
|
milestones: 1,
|
2018-11-20 20:47:30 +05:30
|
|
|
first_issue_labels: 1,
|
|
|
|
services: 1
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when there is an existing build with build token' do
|
|
|
|
before do
|
|
|
|
create(:ci_build, token: 'abcd')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it_behaves_like 'restores project successfully',
|
2019-12-21 20:55:43 +05:30
|
|
|
issues: 1,
|
|
|
|
labels: 2,
|
|
|
|
label_with_priorities: 'A project label',
|
|
|
|
milestones: 1,
|
|
|
|
first_issue_labels: 1
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'when post import action throw non-retriable exception' do
|
|
|
|
let(:exception) { StandardError.new('post_import_error') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
setup_import_export_config('light')
|
|
|
|
expect(project)
|
|
|
|
.to receive(:merge_requests)
|
|
|
|
.and_raise(exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'report post import error' do
|
|
|
|
expect(restored_project_json).to eq(false)
|
|
|
|
expect(shared.errors).to include('post_import_error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when post import action throw retriable exception one time' do
|
|
|
|
let(:exception) { GRPC::DeadlineExceeded.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
setup_import_export_config('light')
|
|
|
|
expect(project)
|
|
|
|
.to receive(:merge_requests)
|
|
|
|
.and_raise(exception)
|
|
|
|
expect(project)
|
|
|
|
.to receive(:merge_requests)
|
|
|
|
.and_call_original
|
|
|
|
expect(restored_project_json).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'restores project successfully',
|
|
|
|
issues: 1,
|
|
|
|
labels: 2,
|
|
|
|
label_with_priorities: 'A project label',
|
|
|
|
milestones: 1,
|
|
|
|
first_issue_labels: 1,
|
|
|
|
services: 1,
|
|
|
|
import_failures: 1
|
|
|
|
|
|
|
|
it 'records the failures in the database' do
|
|
|
|
import_failure = ImportFailure.last
|
|
|
|
|
|
|
|
expect(import_failure.project_id).to eq(project.id)
|
|
|
|
expect(import_failure.relation_key).to be_nil
|
|
|
|
expect(import_failure.relation_index).to be_nil
|
|
|
|
expect(import_failure.exception_class).to eq('GRPC::DeadlineExceeded')
|
|
|
|
expect(import_failure.exception_message).to be_present
|
|
|
|
expect(import_failure.correlation_id_value).not_to be_empty
|
|
|
|
expect(import_failure.created_at).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when the project has overridden params in import data' do
|
2019-12-26 22:10:19 +05:30
|
|
|
before do
|
|
|
|
setup_import_export_config('light')
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it 'handles string versions of visibility_level' do
|
|
|
|
# Project needs to be in a group for visibility level comparison
|
|
|
|
# to happen
|
|
|
|
group = create(:group)
|
|
|
|
project.group = group
|
|
|
|
|
|
|
|
project.create_import_data(data: { override_params: { visibility_level: Gitlab::VisibilityLevel::INTERNAL.to_s } })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'overwrites the params stored in the JSON' do
|
|
|
|
project.create_import_data(data: { override_params: { description: "Overridden" } })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(project.description).to eq("Overridden")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow setting params that are excluded from import_export settings' do
|
|
|
|
project.create_import_data(data: { override_params: { lfs_enabled: true } })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(project.lfs_enabled).to be_falsey
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
it 'overrides project feature access levels' do
|
|
|
|
access_level_keys = project.project_feature.attributes.keys.select { |a| a =~ /_access_level/ }
|
|
|
|
|
|
|
|
# `pages_access_level` is not included, since it is not available in the public API
|
|
|
|
# and has a dependency on project's visibility level
|
|
|
|
# see ProjectFeature model
|
|
|
|
access_level_keys.delete('pages_access_level')
|
|
|
|
|
|
|
|
disabled_access_levels = Hash[access_level_keys.collect { |item| [item, 'disabled'] }]
|
|
|
|
|
|
|
|
project.create_import_data(data: { override_params: disabled_access_levels })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
access_level_keys.each do |key|
|
|
|
|
expect(project.public_send(key)).to eq(ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'with a project that has a group' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:project) do
|
2017-09-10 17:25:29 +05:30
|
|
|
create(:project,
|
2017-08-17 22:00:37 +05:30
|
|
|
:builds_disabled,
|
|
|
|
:issues_disabled,
|
|
|
|
name: 'project',
|
|
|
|
path: 'project',
|
2019-02-02 18:00:53 +05:30
|
|
|
group: create(:group, visibility_level: Gitlab::VisibilityLevel::PRIVATE))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2019-12-26 22:10:19 +05:30
|
|
|
setup_import_export_config('group')
|
|
|
|
expect(restored_project_json).to eq(true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it_behaves_like 'restores project successfully',
|
2020-03-13 15:44:24 +05:30
|
|
|
issues: 3,
|
2019-09-30 21:07:59 +05:30
|
|
|
labels: 2,
|
2019-12-21 20:55:43 +05:30
|
|
|
label_with_priorities: 'A project label',
|
2018-11-08 19:23:39 +05:30
|
|
|
milestones: 2,
|
2018-03-17 18:26:18 +05:30
|
|
|
first_issue_labels: 1
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like 'restores group correctly',
|
2018-11-08 19:23:39 +05:30
|
|
|
labels: 0,
|
|
|
|
milestones: 0,
|
2018-03-17 18:26:18 +05:30
|
|
|
first_issue_labels: 1
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it 'restores issue states' do
|
|
|
|
expect(project.issues.with_state(:closed).count).to eq(1)
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(project.issues.with_state(:opened).count).to eq(2)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
context 'with existing group models' do
|
|
|
|
let!(:project) do
|
|
|
|
create(:project,
|
|
|
|
:builds_disabled,
|
|
|
|
:issues_disabled,
|
|
|
|
name: 'project',
|
|
|
|
path: 'project',
|
|
|
|
group: create(:group))
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2019-12-26 22:10:19 +05:30
|
|
|
setup_import_export_config('light')
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'does not import any templated services' do
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(project.services.where(template: true).count).to eq(0)
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'imports labels' do
|
|
|
|
create(:group_label, name: 'Another label', group: project.group)
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::ImportExport::Shared).not_to receive(:error)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(project.labels.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'imports milestones' do
|
|
|
|
create(:milestone, name: 'A milestone', group: project.group)
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::ImportExport::Shared).not_to receive(:error)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(project.group.milestones.count).to eq(1)
|
|
|
|
expect(project.milestones.count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with clashing milestones on IID' do
|
|
|
|
let!(:project) do
|
|
|
|
create(:project,
|
|
|
|
:builds_disabled,
|
|
|
|
:issues_disabled,
|
|
|
|
name: 'project',
|
|
|
|
path: 'project',
|
|
|
|
group: create(:group))
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
before do
|
|
|
|
setup_import_export_config('milestone-iid')
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'preserves the project milestone IID' do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect_any_instance_of(Gitlab::ImportExport::Shared).not_to receive(:error)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(project.milestones.count).to eq(2)
|
|
|
|
expect(Milestone.find_by_title('Another milestone').iid).to eq(1)
|
|
|
|
expect(Milestone.find_by_title('Group-level milestone').iid).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
context 'with external authorization classification labels' do
|
2019-12-26 22:10:19 +05:30
|
|
|
before do
|
|
|
|
setup_import_export_config('light')
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'converts empty external classification authorization labels to nil' do
|
|
|
|
project.create_import_data(data: { override_params: { external_authorization_classification_label: "" } })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(project.external_authorization_classification_label).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'preserves valid external classification authorization labels' do
|
|
|
|
project.create_import_data(data: { override_params: { external_authorization_classification_label: "foobar" } })
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(restored_project_json).to eq(true)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(project.external_authorization_classification_label).to eq("foobar")
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2019-02-02 18:00:53 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'Minimal JSON' do
|
2019-02-02 18:00:53 +05:30
|
|
|
let(:project) { create(:project) }
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:user) { create(:user) }
|
2019-02-02 18:00:53 +05:30
|
|
|
let(:tree_hash) { { 'visibility_level' => visibility } }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:restorer) do
|
|
|
|
described_class.new(user: user, shared: shared, project: project)
|
|
|
|
end
|
2019-02-02 18:00:53 +05:30
|
|
|
|
|
|
|
before do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer).to receive(:read_tree_hash) { tree_hash }
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'no group visibility' do
|
|
|
|
let(:visibility) { Gitlab::VisibilityLevel::PRIVATE }
|
|
|
|
|
|
|
|
it 'uses the project visibility' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(visibility)
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'with restricted internal visibility' do
|
|
|
|
describe 'internal project' do
|
|
|
|
let(:visibility) { Gitlab::VisibilityLevel::INTERNAL }
|
|
|
|
|
|
|
|
it 'uses private visibility' do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 18:00:53 +05:30
|
|
|
context 'with group visibility' do
|
|
|
|
before do
|
|
|
|
group = create(:group, visibility_level: group_visibility)
|
|
|
|
|
|
|
|
project.update(group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'private group visibility' do
|
|
|
|
let(:group_visibility) { Gitlab::VisibilityLevel::PRIVATE }
|
|
|
|
let(:visibility) { Gitlab::VisibilityLevel::PUBLIC }
|
|
|
|
|
|
|
|
it 'uses the group visibility' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(group_visibility)
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'public group visibility' do
|
|
|
|
let(:group_visibility) { Gitlab::VisibilityLevel::PUBLIC }
|
|
|
|
let(:visibility) { Gitlab::VisibilityLevel::PRIVATE }
|
|
|
|
|
|
|
|
it 'uses the project visibility' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(visibility)
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'internal group visibility' do
|
|
|
|
let(:group_visibility) { Gitlab::VisibilityLevel::INTERNAL }
|
|
|
|
let(:visibility) { Gitlab::VisibilityLevel::PUBLIC }
|
|
|
|
|
|
|
|
it 'uses the group visibility' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(group_visibility)
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
context 'with restricted internal visibility' do
|
|
|
|
it 'sets private visibility' do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(restorer.restore).to eq(true)
|
|
|
|
expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-02 18:00:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
context 'JSON with invalid records' do
|
|
|
|
subject(:restored_project_json) { project_tree_restorer.restore }
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') }
|
|
|
|
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
setup_import_export_config('with_invalid_records')
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when failures occur because a relation fails to be processed' do
|
|
|
|
it_behaves_like 'restores project successfully',
|
|
|
|
issues: 0,
|
|
|
|
labels: 0,
|
|
|
|
label_with_priorities: nil,
|
|
|
|
milestones: 1,
|
|
|
|
first_issue_labels: 0,
|
|
|
|
services: 0,
|
|
|
|
import_failures: 1
|
|
|
|
|
|
|
|
it 'records the failures in the database' do
|
|
|
|
import_failure = ImportFailure.last
|
|
|
|
|
|
|
|
expect(import_failure.project_id).to eq(project.id)
|
|
|
|
expect(import_failure.relation_key).to eq('milestones')
|
|
|
|
expect(import_failure.relation_index).to be_present
|
|
|
|
expect(import_failure.exception_class).to eq('ActiveRecord::RecordInvalid')
|
|
|
|
expect(import_failure.exception_message).to be_present
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(import_failure.correlation_id_value).not_to be_empty
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(import_failure.created_at).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|