Commit 09813909 authored by Matija Čupić's avatar Matija Čupić

Expose test_reports in PipelineDetailsEntity

Exposes test report data in the PipelineDetailsEntity. This includes but
is not limited to the total running time, total test count and total
status.
parent 7f9c8d91
No related merge requests found
......@@ -7,6 +7,9 @@ class PipelineDetailsEntity < PipelineEntity
expose :details do
expose :artifacts, using: BuildArtifactEntity
expose :test_reports, using: TestReportEntity do |pipeline|
pipeline.test_reports.total_count.zero? ? nil : pipeline.test_reports
end
expose :manual_actions, using: BuildActionEntity
expose :scheduled_actions, using: BuildActionEntity
end
......
# frozen_string_literal: true
class TestReportEntity < Grape::Entity
expose :total_time
expose :total_count
expose :success_count
expose :failed_count
expose :skipped_count
expose :error_count
expose :test_suites, using: TestSuiteEntity do |report|
report.test_suites.values
end
end
# frozen_string_literal: true
class TestSuiteEntity < Grape::Entity
expose :name
expose :total_time
expose :total_count
expose :success_count
expose :failed_count
expose :skipped_count
expose :error_count
expose :test_cases, using: TestCaseEntity do |test_suite|
test_suite.test_cases.values.flat_map(&:values)
end
end
......@@ -31,7 +31,7 @@ describe PipelineDetailsEntity do
expect(subject[:details])
.to include :duration, :finished_at
expect(subject[:details])
.to include :stages, :artifacts, :manual_actions, :scheduled_actions
.to include :stages, :artifacts, :test_reports, :manual_actions, :scheduled_actions
expect(subject[:details][:status]).to include :icon, :favicon, :text, :label
end
......@@ -113,6 +113,16 @@ describe PipelineDetailsEntity do
end
end
context 'when pipeline has test reports' do
let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
it 'contains test reports' do
expect(subject).to include(:details)
expect(subject[:details]).to include(:test_reports)
expect(subject[:details][:test_reports][:total_time]).to eq(pipeline.test_reports.total_time)
end
end
context 'when pipeline has YAML errors' do
let(:pipeline) do
create(:ci_pipeline, config: { rspec: { invalid: :value } })
......
......@@ -158,7 +158,7 @@ describe PipelineSerializer do
it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject }
expected_queries = Gitlab.ee? ? 38 : 31
expected_queries = Gitlab.ee? ? 40 : 33
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
......@@ -179,7 +179,7 @@ describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-foss/issues/46368
expected_queries = Gitlab.ee? ? 44 : 38
expected_queries = Gitlab.ee? ? 46 : 40
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
end
......
# frozen_string_literal: true
require 'spec_helper'
describe TestReportEntity do
let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
let(:entity) { described_class.new(pipeline.test_reports) }
describe '#as_json' do
subject(:as_json) { entity.as_json }
it 'contains the total time' do
expect(as_json).to include(:total_time)
end
it 'contains the counts' do
expect(as_json).to include(:total_count, :success_count, :failed_count, :skipped_count, :error_count)
end
it 'contains the test suites' do
expect(as_json).to include(:test_suites)
expect(as_json[:test_suites].count).to eq(1)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe TestSuiteEntity do
let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
let(:entity) { described_class.new(pipeline.test_reports.test_suites.values.first) }
describe '#as_json' do
subject(:as_json) { entity.as_json }
it 'contains the suite name' do
expect(as_json).to include(:name)
end
it 'contains the total time' do
expect(as_json).to include(:total_time)
end
it 'contains the counts' do
expect(as_json).to include(:total_count, :success_count, :failed_count, :skipped_count, :error_count)
end
it 'contains the test cases' do
expect(as_json).to include(:test_cases)
expect(as_json[:test_cases].count).to eq(4)
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