diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 09:13:39 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 09:13:39 +0300 |
commit | 85af3ea21a5a772cb22756190268ba3f921a6400 (patch) | |
tree | 4231bb48df2693c9600b5c5b7dabb9bae41c1d3e /spec | |
parent | 1f53cf7cf0cb53b5d69ab141fa9020356e62027e (diff) |
Added unique identifier to calculate_reactive_cache. Decoupled comparison logic to service. Fixed N+1 select queries.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/ci/build_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 19 | ||||
-rw-r--r-- | spec/services/ci/compare_test_reports_service_spec.rb | 55 |
3 files changed, 63 insertions, 13 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 7137c07c55d..858e448a3d8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2845,7 +2845,7 @@ describe Ci::Build do context 'when build does not have test reports' do it 'raises an error' do - expect { subject }.to raise_error(ArgumentError) + expect { subject }.to raise_error(NoMethodError) end end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 161c0b48626..d28250dbab7 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1127,7 +1127,9 @@ describe MergeRequest do end context 'when head pipeline has test reports' do - let!(:job_artifact) { create(:ci_job_artifact, :junit, job: head_pipeline.builds.first, project: project) } + before do + create(:ci_job_artifact, :junit, job: head_pipeline.builds.first, project: project) + end context 'when reactive cache worker is parsing asynchronously' do it 'returns status' do @@ -1141,17 +1143,10 @@ describe MergeRequest do end it 'returns status and data' do - expect(subject[:status]).to eq(:parsed) - expect(subject[:data]).to be_a(String) - end + expect_any_instance_of(Ci::CompareTestReportsService) + .to receive(:execute).with(base_pipeline.iid, head_pipeline.iid) - context 'when test reports contains invalid data' do - let!(:job_artifact) { create(:ci_job_artifact, :junit_with_corrupted_data, job: head_pipeline.builds.first, project: project) } - - it 'returns status and error message' do - expect(subject[:status]).to eq(:error) - expect(subject[:status_reason]).to eq('Invalid XML data') - end + subject end end end @@ -1159,7 +1154,7 @@ describe MergeRequest do context 'when head pipeline does not have test reports' do it 'returns status and error message' do expect(subject[:status]).to eq(:error) - expect(subject[:status_reason]).to eq('head pipeline does not have test reports') + expect(subject[:status_reason]).to eq('This merge request does not have test reports') end end end diff --git a/spec/services/ci/compare_test_reports_service_spec.rb b/spec/services/ci/compare_test_reports_service_spec.rb new file mode 100644 index 00000000000..6278774f446 --- /dev/null +++ b/spec/services/ci/compare_test_reports_service_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Ci::CompareTestReportsService do + let(:service) { described_class.new(project) } + let(:project) { create(:project, :repository) } + let(:merge_request) { create(:merge_request, source_project: project) } + + describe '#execute' do + subject { service.execute(base_pipeline.iid, head_pipeline.iid) } + + let!(:base_pipeline) do + create(:ci_pipeline, + :success, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_base_sha).tap do |pipeline| + merge_request.update!(head_pipeline_id: pipeline.id) + create(:ci_build, name: 'rspec', pipeline: pipeline, project: project) + end + end + + let!(:head_pipeline) do + create(:ci_pipeline, + :success, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha).tap do |pipeline| + merge_request.update!(head_pipeline_id: pipeline.id) + create(:ci_build, name: 'rspec', pipeline: pipeline, project: project) + end + end + + context 'when head pipeline has test reports' do + before do + create(:ci_job_artifact, :junit, job: head_pipeline.builds.first, project: project) + end + + it 'returns status and data' do + expect(subject[:status]).to eq(:parsed) + expect(subject[:data]).to match_schema('entities/test_reports_comparer') + end + end + + context 'when head pipeline has corrupted test reports' do + before do + create(:ci_job_artifact, :junit_with_corrupted_data, job: head_pipeline.builds.first, project: project) + end + + it 'returns status and error message' do + expect(subject[:status]).to eq(:error) + expect(subject[:status_reason]).to eq('Failed to parse XML') + end + end + end +end |