2020-11-24 15:15:51 +05:30
|
|
|
#!/usr/bin/env ruby
|
2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
require 'set'
|
|
|
|
|
|
|
|
# These tests run a sanity check on the mapping file `tests.yml`
|
|
|
|
# used with the `test_file_finder` gem (`tff`) to identify matching test files.
|
|
|
|
# The verification depend on the presence of actual test files,
|
|
|
|
# so they would fail if one of the test files mentioned here is deleted.
|
|
|
|
# To minimize the chance of this test failing due to unrelated changes,
|
2021-04-29 21:17:54 +05:30
|
|
|
# the test files are chosen to be critical files that are unlikely to be deleted in a typical merge request
|
2020-11-24 15:15:51 +05:30
|
|
|
tests = [
|
|
|
|
{
|
|
|
|
explanation: 'EE code should map to respective spec',
|
|
|
|
source: 'ee/app/controllers/admin/licenses_controller.rb',
|
|
|
|
expected: ['ee/spec/controllers/admin/licenses_controller_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'FOSS code should map to respective spec',
|
|
|
|
source: 'app/finders/admin/projects_finder.rb',
|
|
|
|
expected: ['spec/finders/admin/projects_finder_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'EE extension should map to its EE extension spec and its FOSS class spec',
|
|
|
|
source: 'ee/app/finders/ee/projects_finder.rb',
|
|
|
|
expected: ['ee/spec/finders/ee/projects_finder_spec.rb', 'spec/finders/projects_finder_spec.rb']
|
|
|
|
},
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
{
|
|
|
|
explanation: 'EE lib should map to respective spec.',
|
|
|
|
source: 'ee/lib/world.rb',
|
|
|
|
expected: ['ee/spec/lib/world_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/368628',
|
|
|
|
source: 'lib/gitlab/usage_data_counters/foo.rb',
|
|
|
|
expected: ['spec/lib/gitlab/usage_data_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/54#note_1160811638',
|
|
|
|
source: 'lib/gitlab/ci/config/base.rb',
|
|
|
|
expected: ['spec/lib/gitlab/ci/yaml_processor_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/54#note_1160811638',
|
|
|
|
source: 'ee/lib/gitlab/ci/config/base.rb',
|
|
|
|
expected: ['spec/lib/gitlab/ci/yaml_processor_spec.rb', 'ee/spec/lib/gitlab/ci/yaml_processor_spec.rb']
|
|
|
|
},
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
{
|
|
|
|
explanation: 'FOSS lib should map to respective spec',
|
|
|
|
source: 'lib/gitaly/server.rb',
|
|
|
|
expected: ['spec/lib/gitaly/server_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'Tooling should map to respective spec',
|
2021-03-08 18:12:59 +05:30
|
|
|
source: 'tooling/lib/tooling/helm3_client.rb',
|
|
|
|
expected: ['spec/tooling/lib/tooling/helm3_client_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
{
|
|
|
|
explanation: 'Initializers should map to respective spec',
|
|
|
|
source: 'config/initializers/action_mailer_hooks.rb',
|
|
|
|
expected: ['spec/initializers/action_mailer_hooks_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'DB structure should map to schema spec',
|
|
|
|
source: 'db/structure.sql',
|
|
|
|
expected: ['spec/db/schema_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'Migration should map to its non-timestamped spec',
|
2023-04-23 21:23:45 +05:30
|
|
|
source: 'db/migrate/20221014034338_populate_releases_access_level_from_repository.rb',
|
|
|
|
expected: ['spec/migrations/populate_releases_access_level_from_repository_spec.rb']
|
2023-03-04 22:38:38 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'Migration should map to its timestamped spec',
|
|
|
|
source: 'db/post_migrate/20210915022415_cleanup_bigint_conversion_for_ci_builds.rb',
|
|
|
|
expected: ['spec/migrations/20210915022415_cleanup_bigint_conversion_for_ci_builds_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'FOSS views should map to respective spec',
|
|
|
|
source: 'app/views/admin/dashboard/index.html.haml',
|
|
|
|
expected: ['spec/views/admin/dashboard/index.html.haml_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'EE views should map to respective spec',
|
|
|
|
source: 'ee/app/views/subscriptions/new.html.haml',
|
|
|
|
expected: ['ee/spec/views/subscriptions/new.html.haml_spec.rb']
|
|
|
|
},
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
{
|
|
|
|
explanation: 'FOSS spec code should map to itself',
|
|
|
|
source: 'spec/models/issue_spec.rb',
|
|
|
|
expected: ['spec/models/issue_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'EE spec code should map to itself',
|
2021-02-22 17:27:13 +05:30
|
|
|
source: 'ee/spec/models/ee/user_spec.rb',
|
|
|
|
expected: ['ee/spec/models/ee/user_spec.rb', 'spec/models/user_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'EE extension spec should map to itself and the FOSS class spec',
|
|
|
|
source: 'ee/spec/services/ee/notification_service_spec.rb',
|
|
|
|
expected: ['ee/spec/services/ee/notification_service_spec.rb', 'spec/services/notification_service_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'FOSS factory should map to factories spec',
|
|
|
|
source: 'spec/factories/users.rb',
|
2023-04-23 21:23:45 +05:30
|
|
|
expected: ['ee/spec/models/factories_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'EE factory should map to factories spec',
|
|
|
|
source: 'ee/spec/factories/users.rb',
|
2023-04-23 21:23:45 +05:30
|
|
|
expected: ['ee/spec/models/factories_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'Whats New should map to its respective spec',
|
|
|
|
source: 'data/whats_new/202101140001_13_08.yml',
|
|
|
|
expected: ['spec/lib/release_highlights/validator_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'The documentation index page is used in this haml_lint spec',
|
|
|
|
source: 'doc/index.md',
|
|
|
|
expected: ['spec/haml_lint/linter/documentation_links_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'Spec for FOSS sidekiq worker',
|
|
|
|
source: 'app/workers/new_worker.rb',
|
|
|
|
expected: ['spec/workers/every_sidekiq_worker_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'Spec for EE sidekiq worker',
|
|
|
|
source: 'ee/app/workers/new_worker.rb',
|
|
|
|
expected: ['spec/workers/every_sidekiq_worker_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'Known events',
|
|
|
|
source: 'lib/gitlab/usage_data_counters/known_events/common.yml',
|
|
|
|
expected: ['spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb', 'spec/lib/gitlab/usage_data_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'FOSS mailer previews',
|
|
|
|
source: 'app/mailers/previews/foo.rb',
|
|
|
|
expected: ['spec/mailers/previews_spec.rb']
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'EE mailer previews',
|
|
|
|
source: 'ee/app/mailers/previews/foo.rb',
|
|
|
|
expected: ['spec/mailers/previews_spec.rb']
|
2022-10-11 01:57:18 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'EE mailer extension previews',
|
|
|
|
source: 'ee/app/mailers/previews/license_mailer_preview.rb',
|
|
|
|
expected: ['spec/mailers/previews_spec.rb']
|
2022-10-11 01:57:18 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-03-04 22:38:38 +05:30
|
|
|
explanation: 'GLFM spec and config files for CE and EE should map to respective markdown snapshot specs',
|
|
|
|
source: 'glfm_specification/foo',
|
|
|
|
expected: ['spec/requests/api/markdown_snapshot_spec.rb', 'ee/spec/requests/api/markdown_snapshot_spec.rb']
|
2023-03-17 16:20:25 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/287#note_1192008962',
|
|
|
|
# Note: The metrics seem to be changed every year or so, so this test will fail once a year or so.
|
|
|
|
# You will need to change the metric below for another metric present in the project.
|
|
|
|
source: 'ee/config/metrics/counts_all/20221114065035_delete_merge_request.yml',
|
|
|
|
expected: ['ee/spec/config/metrics/every_metric_definition_spec.rb']
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
explanation: 'https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/287#note_1192008962',
|
|
|
|
source: 'ee/lib/ee/gitlab/usage_data_counters/known_events/common.yml',
|
|
|
|
expected: ['ee/spec/config/metrics/every_metric_definition_spec.rb']
|
2020-11-24 15:15:51 +05:30
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
class MappingTest
|
|
|
|
def initialize(explanation:, source:, expected:, mapping: 'tests.yml')
|
|
|
|
@explanation = explanation
|
|
|
|
@source = source
|
|
|
|
@mapping = mapping
|
|
|
|
@expected_set = Set.new(expected)
|
|
|
|
@actual_set = Set.new(actual)
|
|
|
|
end
|
|
|
|
|
|
|
|
def passed?
|
|
|
|
expected_set.eql?(actual_set)
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
|
|
|
!passed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message
|
|
|
|
"#{explanation}: #{source}: Expected #{expected_set.to_a}, got #{actual_set.to_a}."
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :explanation, :source, :expected_set, :actual_set, :mapping
|
|
|
|
|
|
|
|
def actual
|
|
|
|
`tff -f #{mapping} #{source}`.split(' ')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
results = tests.map { |test| MappingTest.new(**test) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
failed_tests = results.select(&:failed?)
|
|
|
|
if failed_tests.any?
|
|
|
|
puts <<~MESSAGE
|
|
|
|
tff mapping verification failed:
|
|
|
|
#{failed_tests.map(&:failure_message).join("\n")}
|
|
|
|
MESSAGE
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
puts 'tff mapping verification passed.'
|