debian-mirror-gitlab/app/serializers/test_suite_comparer_entity.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-11-18 11:00:15 +05:30
class TestSuiteComparerEntity < Grape::Entity
2019-09-30 21:07:59 +05:30
DEFAULT_MAX_TESTS = 100
DEFAULT_MIN_TESTS = 10
2018-11-18 11:00:15 +05:30
expose :name
expose :total_status, as: :status
expose :summary do
expose :total_count, as: :total
expose :resolved_count, as: :resolved
expose :failed_count, as: :failed
2020-03-13 15:44:24 +05:30
expose :error_count, as: :errored
2018-11-18 11:00:15 +05:30
end
2019-09-30 21:07:59 +05:30
# rubocop: disable CodeReuse/ActiveRecord
expose :new_failures, using: TestCaseEntity do |suite|
suite.new_failures.take(max_tests)
end
expose :existing_failures, using: TestCaseEntity do |suite|
suite.existing_failures.take(
max_tests(suite.new_failures))
end
expose :resolved_failures, using: TestCaseEntity do |suite|
suite.resolved_failures.take(
max_tests(suite.new_failures, suite.existing_failures))
end
2020-03-13 15:44:24 +05:30
expose :new_errors, using: TestCaseEntity do |suite|
suite.new_errors.take(max_tests)
end
expose :existing_errors, using: TestCaseEntity do |suite|
suite.existing_errors.take(
max_tests(suite.new_errors))
end
expose :resolved_errors, using: TestCaseEntity do |suite|
suite.resolved_errors.take(
max_tests(suite.new_errors, suite.existing_errors))
end
2019-09-30 21:07:59 +05:30
private
def max_tests(*used)
[DEFAULT_MAX_TESTS - used.map(&:count).sum, DEFAULT_MIN_TESTS].max
end
# rubocop: enable CodeReuse/ActiveRecord
2018-11-18 11:00:15 +05:30
end