Class: GitlabQuality::TestTooling::CodeCoverage::TestFileMappingData

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/code_coverage/test_file_mapping_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_to_sources, tests_to_categories: {}, feature_categories_to_teams: {}) ⇒ TestFileMappingData

Returns a new instance of TestFileMappingData.

Parameters:

  • test_to_sources (Hash<String, Array<String>>)

    Test files mapped to all source files they cover

  • tests_to_categories (Hash<String, Array<String>>) (defaults to: {})

    Test files mapped to their feature categories

  • feature_categories_to_teams (Hash<String, Hash>) (defaults to: {})

    Feature categories mapped to their org hierarchy (group, stage, section)



13
14
15
16
17
# File 'lib/gitlab_quality/test_tooling/code_coverage/test_file_mapping_data.rb', line 13

def initialize(test_to_sources, tests_to_categories: {}, feature_categories_to_teams: {})
  @test_to_sources = test_to_sources
  @tests_to_categories = tests_to_categories
  @feature_categories_to_teams = feature_categories_to_teams
end

Instance Method Details

#as_db_tableArray<Hash<Symbol, String>>

Returns Mapping data formatted for database insertion.

Examples:

Return value

[
  { test_file: "spec/models/user_spec.rb", source_file: "app/models/user.rb",
    category: "team_planning", group: "project_management", stage: "plan", section: "dev" },
  ...
]

Returns:

  • (Array<Hash<Symbol, String>>)

    Mapping data formatted for database insertion



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab_quality/test_tooling/code_coverage/test_file_mapping_data.rb', line 26

def as_db_table
  @test_to_sources.flat_map do |test_file, source_files|
    category = @tests_to_categories[test_file]&.first || ''
    team = @feature_categories_to_teams[category] || {}

    source_files.map do |source_file|
      {
        test_file: test_file,
        source_file: source_file,
        category: category,
        group: team[:group] || '',
        stage: team[:stage] || '',
        section: team[:section] || ''
      }
    end
  end
end