Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-08-03 21:39:48 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2018-08-03 21:39:48 +0300
commit99c033f2888a96267aa0443ad7a07f1f0e861992 (patch)
treea1d7bb68dfaba668987705538bfa4526c473010d /spec/models
parent53ecd2e147eb24f7e53385cb21f0c9759a482d6c (diff)
parentfafd1764ca71156d261a604d64b43d531667cb17 (diff)
Merge branch 'artifact-format-v2-with-parser' into 'master'
Parse junit.xml.gz and calculate the difference between head and base See merge request gitlab-org/gitlab-ce!20576
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/build_spec.rb90
-rw-r--r--spec/models/ci/job_artifact_spec.rb28
-rw-r--r--spec/models/ci/pipeline_spec.rb56
-rw-r--r--spec/models/merge_request_spec.rb101
4 files changed, 275 insertions, 0 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 6955f7f4cd8..32b8755ee9a 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -151,6 +151,42 @@ describe Ci::Build do
end
end
+ describe '.with_test_reports' do
+ subject { described_class.with_test_reports }
+
+ context 'when build has a test report' do
+ let!(:build) { create(:ci_build, :success, :test_reports) }
+
+ it 'selects the build' do
+ is_expected.to eq([build])
+ end
+ end
+
+ context 'when build does not have test reports' do
+ let!(:build) { create(:ci_build, :success, :trace_artifact) }
+
+ it 'does not select the build' do
+ is_expected.to be_empty
+ end
+ end
+
+ context 'when there are multiple builds with test reports' do
+ let!(:builds) { create_list(:ci_build, 5, :success, :test_reports) }
+
+ it 'does not execute a query for selecting job artifact one by one' do
+ recorded = ActiveRecord::QueryRecorder.new do
+ subject.each do |build|
+ Ci::JobArtifact::TEST_REPORT_FILE_TYPES.each do |file_type|
+ build.public_send("job_artifacts_#{file_type}").file.exists?
+ end
+ end
+ end
+
+ expect(recorded.count).to eq(2)
+ end
+ end
+ end
+
describe '#actionize' do
context 'when build is a created' do
before do
@@ -2760,6 +2796,60 @@ describe Ci::Build do
end
end
+ describe '#collect_test_reports!' do
+ subject { build.collect_test_reports!(test_reports) }
+
+ let(:test_reports) { Gitlab::Ci::Reports::TestReports.new }
+
+ it { expect(test_reports.get_suite(build.name).total_count).to eq(0) }
+
+ context 'when build has a test report' do
+ context 'when there is a JUnit test report from rspec test suite' do
+ before do
+ create(:ci_job_artifact, :junit, job: build, project: build.project)
+ end
+
+ it 'parses blobs and add the results to the test suite' do
+ expect { subject }.not_to raise_error
+
+ expect(test_reports.get_suite(build.name).total_count).to eq(4)
+ expect(test_reports.get_suite(build.name).success_count).to be(2)
+ expect(test_reports.get_suite(build.name).failed_count).to be(2)
+ end
+ end
+
+ context 'when there is a JUnit test report from java ant test suite' do
+ before do
+ create(:ci_job_artifact, :junit_with_ant, job: build, project: build.project)
+ end
+
+ it 'parses blobs and add the results to the test suite' do
+ expect { subject }.not_to raise_error
+
+ expect(test_reports.get_suite(build.name).total_count).to eq(3)
+ expect(test_reports.get_suite(build.name).success_count).to be(3)
+ expect(test_reports.get_suite(build.name).failed_count).to be(0)
+ end
+ end
+
+ context 'when there is a corrupted JUnit test report' do
+ before do
+ create(:ci_job_artifact, :junit_with_corrupted_data, job: build, project: build.project)
+ end
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Ci::Parsers::Junit::JunitParserError)
+ end
+ end
+ end
+
+ context 'when build does not have test reports' do
+ it 'raises an error' do
+ expect { subject }.to raise_error(NoMethodError)
+ end
+ end
+ end
+
describe '#artifacts_metadata_entry' do
set(:build) { create(:ci_build, project: project) }
let(:path) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' }
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index 4f34c2e81f8..1bf338f4c70 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -147,6 +147,34 @@ describe Ci::JobArtifact do
end
end
+ describe '#each_blob' do
+ context 'when file format is gzip' do
+ context 'when gzip file contains one file' do
+ let(:artifact) { build(:ci_job_artifact, :junit) }
+
+ it 'iterates blob once' do
+ expect { |b| artifact.each_blob(&b) }.to yield_control.once
+ end
+ end
+
+ context 'when gzip file contains three files' do
+ let(:artifact) { build(:ci_job_artifact, :junit_with_three_testsuites) }
+
+ it 'iterates blob three times' do
+ expect { |b| artifact.each_blob(&b) }.to yield_control.exactly(3).times
+ end
+ end
+ end
+
+ context 'when there are no adapters for the file format' do
+ let(:artifact) { build(:ci_job_artifact, :junit, file_format: :zip) }
+
+ it 'raises an error' do
+ expect { |b| artifact.each_blob(&b) }.to raise_error(described_class::NotSupportedAdapterError)
+ end
+ end
+ end
+
describe '#expire_in' do
subject { artifact.expire_in }
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index a41657b53b7..3512ba6aee5 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1851,6 +1851,62 @@ describe Ci::Pipeline, :mailer do
end
end
+ describe '#has_test_reports?' do
+ subject { pipeline.has_test_reports? }
+
+ context 'when pipeline has builds with test reports' do
+ before do
+ create(:ci_build, pipeline: pipeline, project: project).tap do |build|
+ create(:ci_job_artifact, :junit, job: build, project: build.project)
+ end
+ end
+
+ context 'when pipeline status is running' do
+ let(:pipeline) { create(:ci_pipeline, :running, project: project) }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when pipeline status is success' do
+ let(:pipeline) { create(:ci_pipeline, :success, project: project) }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ context 'when pipeline does not have builds with test reports' do
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#test_reports' do
+ subject { pipeline.test_reports }
+
+ context 'when pipeline has multiple builds with test reports' do
+ before do
+ create(:ci_build, :success, name: 'rspec', pipeline: pipeline, project: project).tap do |build|
+ create(:ci_job_artifact, :junit, job: build, project: build.project)
+ end
+
+ create(:ci_build, :success, name: 'java', pipeline: pipeline, project: project).tap do |build|
+ create(:ci_job_artifact, :junit_with_ant, job: build, project: build.project)
+ end
+ end
+
+ it 'returns test reports with collected data' do
+ expect(subject.total_count).to be(7)
+ expect(subject.success_count).to be(5)
+ expect(subject.failed_count).to be(2)
+ end
+ end
+
+ context 'when pipeline does not have any builds with test reports' do
+ it 'returns empty test reports' do
+ expect(subject.total_count).to be(0)
+ end
+ end
+ end
+
describe '#total_size' do
let!(:build_job1) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:build_job2) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index b0d9d03bf6c..ffdec09deef 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe MergeRequest do
include RepoHelpers
include ProjectForksHelper
+ include ReactiveCachingHelpers
subject { create(:merge_request) }
@@ -1079,6 +1080,86 @@ describe MergeRequest do
end
end
+ describe '#has_test_reports?' do
+ subject { merge_request.has_test_reports? }
+
+ let(:project) { create(:project, :repository) }
+
+ context 'when head pipeline has test reports' do
+ let(:merge_request) { create(:merge_request, :with_test_reports, source_project: project) }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'when head pipeline does not have test reports' do
+ let(:merge_request) { create(:merge_request, source_project: project) }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#compare_test_reports' do
+ subject { merge_request.compare_test_reports }
+
+ let(:project) { create(:project, :repository) }
+ let(:merge_request) { create(:merge_request, source_project: project) }
+
+ let!(:base_pipeline) do
+ create(:ci_pipeline,
+ :with_test_reports,
+ project: project,
+ ref: merge_request.target_branch,
+ sha: merge_request.diff_base_sha)
+ end
+
+ before do
+ merge_request.update!(head_pipeline_id: head_pipeline.id)
+ end
+
+ context 'when head pipeline has test reports' do
+ let!(:head_pipeline) do
+ create(:ci_pipeline,
+ :with_test_reports,
+ project: project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
+ end
+
+ context 'when reactive cache worker is parsing asynchronously' do
+ it 'returns status' do
+ expect(subject[:status]).to eq(:parsing)
+ end
+ end
+
+ context 'when reactive cache worker is inline' do
+ before do
+ synchronous_reactive_cache(merge_request)
+ end
+
+ it 'returns status and data' do
+ expect_any_instance_of(Ci::CompareTestReportsService)
+ .to receive(:execute).with(base_pipeline.iid, head_pipeline.iid)
+
+ subject
+ end
+ end
+ end
+
+ context 'when head pipeline does not have test reports' do
+ let!(:head_pipeline) do
+ create(:ci_pipeline,
+ project: project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
+ end
+
+ it 'returns status and error message' do
+ expect(subject[:status]).to eq(:error)
+ expect(subject[:status_reason]).to eq('This merge request does not have test reports')
+ end
+ end
+ end
+
describe '#all_commit_shas' do
context 'when merge request is persisted' do
let(:all_commit_shas) do
@@ -2010,6 +2091,26 @@ describe MergeRequest do
end
end
+ describe '#base_pipeline' do
+ let(:pipeline_arguments) do
+ {
+ project: project,
+ ref: merge_request.target_branch,
+ sha: merge_request.diff_base_sha
+ }
+ end
+
+ let(:project) { create(:project, :public, :repository) }
+ let(:merge_request) { create(:merge_request, source_project: project) }
+
+ let!(:first_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
+ let!(:last_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
+
+ it 'returns latest pipeline' do
+ expect(merge_request.base_pipeline).to eq(last_pipeline)
+ end
+ end
+
describe '#has_commits?' do
before do
allow(subject.merge_request_diff).to receive(:commits_count)