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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 21:09:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 21:09:44 +0300
commit2c156e3c7bbade01c36eee18327f1ced6eebea79 (patch)
tree115fa8dbf6bc05037378b380311d31acb805f54c /spec/models/ci
parent8e129497b2565b8c595ef4f806d9a9595ca654e5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/ci')
-rw-r--r--spec/models/ci/build_spec.rb47
-rw-r--r--spec/models/ci/job_artifact_spec.rb16
-rw-r--r--spec/models/ci/pipeline_spec.rb53
3 files changed, 114 insertions, 2 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 6c77b16f908..a661aa6e3a9 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -3946,6 +3946,53 @@ describe Ci::Build do
end
end
+ describe '#collect_coverage_reports!' do
+ subject { build.collect_coverage_reports!(coverage_report) }
+
+ let(:coverage_report) { Gitlab::Ci::Reports::CoverageReports.new }
+
+ it { expect(coverage_report.files).to eq({}) }
+
+ context 'when build has a coverage report' do
+ context 'when there is a Cobertura coverage report from simplecov-cobertura' do
+ before do
+ create(:ci_job_artifact, :cobertura, job: build, project: build.project)
+ end
+
+ it 'parses blobs and add the results to the coverage report' do
+ expect { subject }.not_to raise_error
+
+ expect(coverage_report.files.keys).to match_array(['app/controllers/abuse_reports_controller.rb'])
+ expect(coverage_report.files['app/controllers/abuse_reports_controller.rb'].count).to eq(23)
+ end
+ end
+
+ context 'when there is a Cobertura coverage report from gocov-xml' do
+ before do
+ create(:ci_job_artifact, :coverage_gocov_xml, job: build, project: build.project)
+ end
+
+ it 'parses blobs and add the results to the coverage report' do
+ expect { subject }.not_to raise_error
+
+ expect(coverage_report.files.keys).to match_array(['auth/token.go', 'auth/rpccredentials.go'])
+ expect(coverage_report.files['auth/token.go'].count).to eq(49)
+ expect(coverage_report.files['auth/rpccredentials.go'].count).to eq(10)
+ end
+ end
+
+ context 'when there is a corrupted Cobertura coverage report' do
+ before do
+ create(:ci_job_artifact, :coverage_with_corrupted_data, job: build, project: build.project)
+ end
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Ci::Parsers::Coverage::Cobertura::CoberturaParserError)
+ end
+ end
+ end
+ end
+
describe '#report_artifacts' do
subject { build.report_artifacts }
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index 0a7a44b225c..de93c3c1675 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -70,6 +70,22 @@ describe Ci::JobArtifact do
end
end
+ describe '.coverage_reports' do
+ subject { described_class.coverage_reports }
+
+ context 'when there is a coverage report' do
+ let!(:artifact) { create(:ci_job_artifact, :cobertura) }
+
+ it { is_expected.to eq([artifact]) }
+ end
+
+ context 'when there are no coverage reports' do
+ let!(:artifact) { create(:ci_job_artifact, :archive) }
+
+ it { is_expected.to be_empty }
+ end
+ end
+
describe '.erasable' do
subject { described_class.erasable }
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 51a2e2aff67..f18c77988c8 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -344,9 +344,9 @@ describe Ci::Pipeline, :mailer do
end
describe '.with_reports' do
- subject { described_class.with_reports(Ci::JobArtifact.test_reports) }
-
context 'when pipeline has a test report' do
+ subject { described_class.with_reports(Ci::JobArtifact.test_reports) }
+
let!(:pipeline_with_report) { create(:ci_pipeline, :with_test_reports) }
it 'selects the pipeline' do
@@ -354,7 +354,19 @@ describe Ci::Pipeline, :mailer do
end
end
+ context 'when pipeline has a coverage report' do
+ subject { described_class.with_reports(Ci::JobArtifact.coverage_reports) }
+
+ let!(:pipeline_with_report) { create(:ci_pipeline, :with_coverage_reports) }
+
+ it 'selects the pipeline' do
+ is_expected.to eq([pipeline_with_report])
+ end
+ end
+
context 'when pipeline does not have metrics reports' do
+ subject { described_class.with_reports(Ci::JobArtifact.test_reports) }
+
let!(:pipeline_without_report) { create(:ci_empty_pipeline) }
it 'does not select the pipeline' do
@@ -2730,6 +2742,43 @@ describe Ci::Pipeline, :mailer do
end
end
+ describe '#coverage_reports' do
+ subject { pipeline.coverage_reports }
+
+ context 'when pipeline has multiple builds with coverage reports' do
+ let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline, project: project) }
+ let!(:build_golang) { create(:ci_build, :success, name: 'golang', pipeline: pipeline, project: project) }
+
+ before do
+ create(:ci_job_artifact, :cobertura, job: build_rspec, project: project)
+ create(:ci_job_artifact, :coverage_gocov_xml, job: build_golang, project: project)
+ end
+
+ it 'returns coverage reports with collected data' do
+ expect(subject.files.keys).to match_array([
+ "auth/token.go",
+ "auth/rpccredentials.go",
+ "app/controllers/abuse_reports_controller.rb"
+ ])
+ end
+
+ context 'when builds are retried' do
+ let!(:build_rspec) { create(:ci_build, :retried, :success, name: 'rspec', pipeline: pipeline, project: project) }
+ let!(:build_golang) { create(:ci_build, :retried, :success, name: 'golang', pipeline: pipeline, project: project) }
+
+ it 'does not take retried builds into account' do
+ expect(subject.files).to eql({})
+ end
+ end
+ end
+
+ context 'when pipeline does not have any builds with coverage reports' do
+ it 'returns empty coverage reports' do
+ expect(subject.files).to eql({})
+ 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) }