Commit 39a356f4 authored by Thong Kuah's avatar Thong Kuah

Merge branch '39536-cover-relations-for-import' into 'master'

Improve project Import coverage

Closes #39536

See merge request gitlab-org/gitlab!22251
parents 9303948a 5202fae7
...@@ -462,8 +462,23 @@ ...@@ -462,8 +462,23 @@
"protected_branches":[ "protected_branches":[
], ],
"protected_environments":[ "protected_environments": [
{
"id": 14,
"created_at": "2017-10-19T15:36:23.466Z",
"updated_at": "2017-10-19T15:36:23.466Z",
"name": "production",
"deploy_access_levels": [
{
"id": 21,
"created_at": "2017-10-19T15:36:23.466Z",
"updated_at": "2017-10-19T15:36:23.466Z",
"access_level": 40,
"user_id": 1,
"group_id": null
}
]
}
], ],
"protected_tags":[ "protected_tags":[
......
...@@ -126,5 +126,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -126,5 +126,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end end
end end
end end
it 'restores `protected_environments` with `deploy_access_levels`' do
aggregate_failures do
expect(project.protected_environments.count).to eq(1)
protected_env = project.protected_environments.first
expect(protected_env.deploy_access_levels.count).to eq(1)
end
end
end end
end end
...@@ -2002,7 +2002,7 @@ ...@@ -2002,7 +2002,7 @@
}, },
{ {
"id": 31, "id": 31,
"title": "Libero nam magnam incidunt eaque placeat error et.", "title": "issue_with_timelogs",
"author_id": 16, "author_id": 16,
"project_id": 5, "project_id": 5,
"created_at": "2016-06-14T15:02:07.280Z", "created_at": "2016-06-14T15:02:07.280Z",
...@@ -2016,6 +2016,16 @@ ...@@ -2016,6 +2016,16 @@
"confidential": false, "confidential": false,
"due_date": null, "due_date": null,
"moved_to_id": null, "moved_to_id": null,
"timelogs": [
{
"id": 1,
"time_spent": 72000,
"user_id": 1,
"created_at": "2019-12-27T09:15:22.302Z",
"updated_at": "2019-12-27T09:15:22.302Z",
"spent_at": "2019-12-27T00:00:00.000Z"
}
],
"notes": [ "notes": [
{ {
"id": 423, "id": 423,
...@@ -2347,7 +2357,30 @@ ...@@ -2347,7 +2357,30 @@
] ]
} }
], ],
"releases": [], "releases": [
{
"id": 1,
"tag": "release-1.1",
"description": "Some release notes",
"project_id": 5,
"created_at": "2019-12-26T10:17:14.621Z",
"updated_at": "2019-12-26T10:17:14.621Z",
"author_id": 1,
"name": "release-1.1",
"sha": "901de3a8bd5573f4a049b1457d28bc1592ba6bf9",
"released_at": "2019-12-26T10:17:14.615Z",
"links": [
{
"id": 1,
"release_id" : 1,
"url": "http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download",
"name": "release-1.1.dmg",
"created_at": "2019-12-26T10:17:14.621Z",
"updated_at": "2019-12-26T10:17:14.621Z"
}
]
}
],
"project_members": [ "project_members": [
{ {
"id": 36, "id": 36,
...@@ -6816,6 +6849,40 @@ ...@@ -6816,6 +6849,40 @@
"duration": null, "duration": null,
"stages": [ "stages": [
] ]
},
{
"id": 42,
"project_id": 5,
"ref": "master",
"sha": "ce84140e8b878ce6e7c4d298c7202ff38170e3ac",
"before_sha": null,
"push_data": null,
"created_at": "2016-03-22T15:20:35.763Z",
"updated_at": "2016-03-22T15:20:35.763Z",
"tag": false,
"yaml_errors": null,
"committed_at": null,
"status": "failed",
"started_at": null,
"finished_at": null,
"duration": null,
"stages": [
],
"source": "external_pull_request_event",
"external_pull_request":
{
"id": 3,
"pull_request_iid": 4,
"source_branch": "feature",
"target_branch": "master",
"source_repository": "the-repository",
"target_repository": "the-repository",
"source_sha": "ce84140e8b878ce6e7c4d298c7202ff38170e3ac",
"target_sha": "a09386439ca39abe575675ffd4b89ae824fec22f",
"status": "open",
"created_at": "2016-03-22T15:20:35.763Z",
"updated_at": "2016-03-22T15:20:35.763Z"
}
} }
], ],
"triggers": [ "triggers": [
...@@ -6835,6 +6902,21 @@ ...@@ -6835,6 +6902,21 @@
"updated_at": "2017-01-16T15:25:29.637Z" "updated_at": "2017-01-16T15:25:29.637Z"
} }
], ],
"pipeline_schedules": [
{
"id": 1,
"description": "Schedule Description",
"ref": "master",
"cron": "0 4 * * 0",
"cron_timezone": "UTC",
"next_run_at": "2019-12-29T04:19:00.000Z",
"project_id": 5,
"owner_id": 1,
"active": true,
"created_at": "2019-12-26T10:14:57.778Z",
"updated_at": "2019-12-26T10:14:57.778Z"
}
],
"container_expiration_policy": { "container_expiration_policy": {
"created_at": "2019-12-13 13:45:04 UTC", "created_at": "2019-12-13 13:45:04 UTC",
"updated_at": "2019-12-13 13:45:04 UTC", "updated_at": "2019-12-13 13:45:04 UTC",
...@@ -7354,6 +7436,33 @@ ...@@ -7354,6 +7436,33 @@
"ci_cd_settings": { "ci_cd_settings": {
"group_runners_enabled": false "group_runners_enabled": false
}, },
"auto_devops": {
"id": 1,
"created_at": "2017-10-19T15:36:23.466Z",
"updated_at": "2017-10-19T15:36:23.466Z",
"enabled": null,
"deploy_strategy": "continuous"
},
"error_tracking_setting": {
"api_url": "https://gitlab.example.com/api/0/projects/sentry-org/sentry-project",
"project_name": "Sentry Project",
"organization_name": "Sentry Org"
},
"external_pull_requests": [
{
"id": 3,
"pull_request_iid": 4,
"source_branch": "feature",
"target_branch": "master",
"source_repository": "the-repository",
"target_repository": "the-repository",
"source_sha": "ce84140e8b878ce6e7c4d298c7202ff38170e3ac",
"target_sha": "a09386439ca39abe575675ffd4b89ae824fec22f",
"status": "open",
"created_at": "2019-12-24T14:04:50.053Z",
"updated_at": "2019-12-24T14:05:18.138Z"
}
],
"boards": [ "boards": [
{ {
"id": 29, "id": 29,
......
...@@ -116,6 +116,15 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -116,6 +116,15 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(Issue.find_by(title: 'Issue without assignees').assignees).to be_empty expect(Issue.find_by(title: 'Issue without assignees').assignees).to be_empty
end end
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
it 'contains the merge access levels on a protected branch' do it 'contains the merge access levels on a protected branch' do
expect(ProtectedBranch.first.merge_access_levels).not_to be_empty expect(ProtectedBranch.first.merge_access_levels).not_to be_empty
end end
...@@ -229,6 +238,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -229,6 +238,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(@project.ci_cd_settings.group_runners_enabled?).to eq(false) expect(@project.ci_cd_settings.group_runners_enabled?).to eq(false)
end end
it 'restores `auto_devops`' do
expect(@project.auto_devops_enabled?).to eq(true)
expect(@project.auto_devops.deploy_strategy).to eq('continuous')
end
it 'restores the correct service' do it 'restores the correct service' do
expect(CustomIssueTrackerService.first).not_to be_nil expect(CustomIssueTrackerService.first).not_to be_nil
end end
...@@ -268,6 +282,55 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -268,6 +282,55 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end end
end end
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
context 'Merge requests' do context 'Merge requests' do
it 'always has the new project as a target' do it 'always has the new project as a target' do
expect(MergeRequest.find_by_title('MR1').target_project).to eq(@project) expect(MergeRequest.find_by_title('MR1').target_project).to eq(@project)
...@@ -321,9 +384,9 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -321,9 +384,9 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end end
it 'has the correct number of pipelines and statuses' do it 'has the correct number of pipelines and statuses' do
expect(@project.ci_pipelines.size).to eq(6) expect(@project.ci_pipelines.size).to eq(7)
@project.ci_pipelines.order(:id).zip([2, 2, 2, 2, 2, 0]) @project.ci_pipelines.order(:id).zip([2, 2, 2, 2, 2, 0, 0])
.each do |(pipeline, expected_status_size)| .each do |(pipeline, expected_status_size)|
expect(pipeline.statuses.size).to eq(expected_status_size) expect(pipeline.statuses.size).to eq(expected_status_size)
end end
...@@ -332,7 +395,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -332,7 +395,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
context 'when restoring hierarchy of pipeline, stages and jobs' do context 'when restoring hierarchy of pipeline, stages and jobs' do
it 'restores pipelines' do it 'restores pipelines' do
expect(Ci::Pipeline.all.count).to be 6 expect(Ci::Pipeline.all.count).to be 7
end end
it 'restores pipeline stages' do it 'restores pipeline stages' do
...@@ -358,6 +421,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -358,6 +421,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
it 'restores a Hash for CommitStatus options' do it 'restores a Hash for CommitStatus options' do
expect(CommitStatus.all.map(&:options).compact).to all(be_a(Hash)) expect(CommitStatus.all.map(&:options).compact).to all(be_a(Hash))
end end
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
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment