Skip to content
Snippets Groups Projects
Commit cec1e3eb authored by James Lopez's avatar James Lopez
Browse files

create lighter version of JSON and reuse initial restore in spec to speed up run

parent 35b31ba8
No related branches found
No related tags found
No related merge requests found
{
"description": "Nisi et repellendus ut enim quo accusamus vel magnam.",
"visibility_level": 10,
"archived": false,
"labels": [
{
"id": 2,
"title": "test2",
"color": "#428bca",
"project_id": 8,
"created_at": "2016-07-22T08:55:44.161Z",
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
"description": "",
"type": "ProjectLabel",
"priorities": [
]
},
{
"id": 3,
"title": "test3",
"color": "#428bca",
"group_id": 8,
"created_at": "2016-07-22T08:55:44.161Z",
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
"description": "",
"project_id": null,
"type": "GroupLabel",
"priorities": [
{
"id": 1,
"project_id": 5,
"label_id": 1,
"priority": 1,
"created_at": "2016-10-18T09:35:43.338Z",
"updated_at": "2016-10-18T09:35:43.338Z"
}
]
}
],
"snippets": [
],
"hooks": [
]
}
\ No newline at end of file
Loading
@@ -3,24 +3,27 @@ include ImportExport::CommonUtil
Loading
@@ -3,24 +3,27 @@ include ImportExport::CommonUtil
   
describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
describe 'restore project tree' do describe 'restore project tree' do
let(:user) { create(:user) } before(:all) do
let(:namespace) { create(:namespace, owner: user) } user = create(:user)
let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: "", project_path: 'path') }
let!(:project) { create(:empty_project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') } RSpec::Mocks.with_temporary_scope do
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) } @shared = Gitlab::ImportExport::Shared.new(relative_path: "", project_path: 'path')
let(:restored_project_json) { project_tree_restorer.restore } allow(@shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/')
project = create(:empty_project, :builds_disabled, :issues_disabled, name: 'project', path: 'project')
project_tree_restorer = described_class.new(user: user, shared: @shared, project: project)
@restored_project_json = project_tree_restorer.restore
end
end
   
before do before do
allow(shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/')
end end
   
context 'JSON' do context 'JSON' do
it 'restores models based on JSON' do it 'restores models based on JSON' do
expect(restored_project_json).to be true expect(@restored_project_json).to be true
end end
   
it 'restore correct project features' do it 'restore correct project features' do
restored_project_json
project = Project.find_by_path('project') project = Project.find_by_path('project')
   
expect(project.project_feature.issues_access_level).to eq(ProjectFeature::DISABLED) expect(project.project_feature.issues_access_level).to eq(ProjectFeature::DISABLED)
Loading
@@ -31,62 +34,42 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
Loading
@@ -31,62 +34,42 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
end end
   
it 'has the same label associated to two issues' do it 'has the same label associated to two issues' do
restored_project_json
expect(ProjectLabel.find_by_title('test2').issues.count).to eq(2) expect(ProjectLabel.find_by_title('test2').issues.count).to eq(2)
end end
   
it 'has milestones associated to two separate issues' do it 'has milestones associated to two separate issues' do
restored_project_json
expect(Milestone.find_by_description('test milestone').issues.count).to eq(2) expect(Milestone.find_by_description('test milestone').issues.count).to eq(2)
end end
   
it 'creates a valid pipeline note' do it 'creates a valid pipeline note' do
restored_project_json
expect(Ci::Pipeline.first.notes).not_to be_empty expect(Ci::Pipeline.first.notes).not_to be_empty
end end
   
it 'restores pipelines with missing ref' do it 'restores pipelines with missing ref' do
restored_project_json
expect(Ci::Pipeline.where(ref: nil)).not_to be_empty expect(Ci::Pipeline.where(ref: nil)).not_to be_empty
end end
   
it 'restores the correct event with symbolised data' do it 'restores the correct event with symbolised data' do
restored_project_json
expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty
end end
   
it 'preserves updated_at on issues' do it 'preserves updated_at on issues' do
restored_project_json
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first 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') expect(issue.reload.updated_at.to_s).to eq('2016-06-14 15:02:47 UTC')
end end
   
it 'contains the merge access levels on a protected branch' do it 'contains the merge access levels on a protected branch' do
restored_project_json
expect(ProtectedBranch.first.merge_access_levels).not_to be_empty expect(ProtectedBranch.first.merge_access_levels).not_to be_empty
end end
   
it 'contains the push access levels on a protected branch' do it 'contains the push access levels on a protected branch' do
restored_project_json
expect(ProtectedBranch.first.push_access_levels).not_to be_empty expect(ProtectedBranch.first.push_access_levels).not_to be_empty
end end
   
context 'event at forth level of the tree' do context 'event at forth level of the tree' do
let(:event) { Event.where(title: 'test levels').first } let(:event) { Event.where(title: 'test levels').first }
   
before do
restored_project_json
end
it 'restores the event' do it 'restores the event' do
expect(event).not_to be_nil expect(event).not_to be_nil
end end
Loading
@@ -99,77 +82,44 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
Loading
@@ -99,77 +82,44 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
it 'has the correct data for merge request st_diffs' do it 'has the correct data for merge request st_diffs' do
# makes sure we are renaming the custom method +utf8_st_diffs+ into +st_diffs+ # makes sure we are renaming the custom method +utf8_st_diffs+ into +st_diffs+
   
expect { restored_project_json }.to change(MergeRequestDiff.where.not(st_diffs: nil), :count).by(9) expect(MergeRequestDiff.where.not(st_diffs: nil).count).to eq(9)
end end
   
it 'has labels associated to label links, associated to issues' do it 'has labels associated to label links, associated to issues' do
restored_project_json
expect(Label.first.label_links.first.target).not_to be_nil expect(Label.first.label_links.first.target).not_to be_nil
end end
   
it 'has project labels' do it 'has project labels' do
restored_project_json
expect(ProjectLabel.count).to eq(2) expect(ProjectLabel.count).to eq(2)
end end
   
it 'has no group labels' do it 'has no group labels' do
restored_project_json
expect(GroupLabel.count).to eq(0) expect(GroupLabel.count).to eq(0)
end end
   
context 'with group' do
let!(:project) do
create(:empty_project,
:builds_disabled,
:issues_disabled,
name: 'project',
path: 'project',
group: create(:group))
end
it 'has group labels' do
restored_project_json
expect(GroupLabel.count).to eq(1)
end
it 'has label priorities' do
restored_project_json
expect(GroupLabel.first.priorities).not_to be_empty
end
end
it 'has a project feature' do it 'has a project feature' do
restored_project_json expect(Project.first.project_feature).not_to be_nil
expect(project.project_feature).not_to be_nil
end end
   
it 'restores the correct service' do it 'restores the correct service' do
restored_project_json
expect(CustomIssueTrackerService.first).not_to be_nil expect(CustomIssueTrackerService.first).not_to be_nil
end end
   
context 'Merge requests' do context 'Merge requests' do
before do before do
restored_project_json @restored_project_json
end end
   
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.first)
end end
   
it 'has the same source project as originally if source/target are the same' do it 'has the same source project as originally if source/target are the same' do
expect(MergeRequest.find_by_title('MR1').source_project).to eq(project) expect(MergeRequest.find_by_title('MR1').source_project).to eq(Project.first)
end end
   
it 'has the new project as target if source/target differ' do it 'has the new project as target if source/target differ' do
expect(MergeRequest.find_by_title('MR2').target_project).to eq(project) expect(MergeRequest.find_by_title('MR2').target_project).to eq(Project.first)
end end
   
it 'has no source if source/target differ' do it 'has no source if source/target differ' do
Loading
@@ -177,39 +127,71 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
Loading
@@ -177,39 +127,71 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
end end
end end
   
context 'project.json file access check' do context 'tokens are regenerated' do
it 'does not read a symlink' do it 'has a new CI trigger token' do
Dir.mktmpdir do |tmpdir| expect(Ci::Trigger.where(token: 'cdbfasdf44a5958c83654733449e585')).to be_empty
setup_symlink(tmpdir, 'project.json') end
allow(shared).to receive(:export_path).and_call_original
restored_project_json
   
expect(shared.errors.first).not_to include('test') it 'has a new CI build token' do
end expect(Ci::Build.where(token: 'abcd')).to be_empty
end end
end end
end
end
   
context 'when there is an existing build with build token' do context 'Light JSON' do
it 'restores project json correctly' do let(:user) { create(:user) }
create(:ci_build, token: 'abcd') let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: "", project_path: 'path') }
let!(:project) { create(:empty_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 }
   
expect(restored_project_json).to be true before do
end allow(ImportExport).to receive(:project_filename).and_return('project.light.json')
end allow(shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/')
end
context 'project.json file access check' do
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
   
context 'tokens are regenerated' do
before do
restored_project_json restored_project_json
end
   
it 'has a new CI trigger token' do expect(shared.errors.first).not_to include('test')
expect(Ci::Trigger.where(token: 'cdbfasdf44a5958c83654733449e585')).to be_empty
end end
end
end
   
it 'has a new CI build token' do context 'when there is an existing build with build token' do
expect(Ci::Build.where(token: 'abcd')).to be_empty it 'restores project json correctly' do
end create(:ci_build, token: 'abcd')
expect(restored_project_json).to be true
end
end
context 'with group' do
let!(:project) do
create(:empty_project,
:builds_disabled,
:issues_disabled,
name: 'project',
path: 'project',
group: create(:group))
end
before do
restored_project_json
end
it 'has group labels' do
expect(GroupLabel.count).to eq(1)
end
it 'has label priorities' do
expect(GroupLabel.first.priorities).not_to be_empty
end end
end end
end end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment