|
7 | 7 | describe 'consistency validation' do |
8 | 8 | it 'validates that the generated data matches the JSON file' do |
9 | 9 | json_data = JSON.parse(File.read('supported-configurations.json')).transform_keys(&:to_sym) |
10 | | - json_data[:supportedConfigurations].each_value { |config| config.transform_keys!(&:to_sym) } |
11 | | - alias_to_canonical = json_data[:aliases].each_with_object({}) do |(canonical, alias_list), h| |
12 | | - alias_list.each do |alias_name| |
13 | | - raise "The alias #{alias_name} is already used for #{h[alias_name]}." if h[alias_name] |
| 10 | + aliases = {} |
| 11 | + deprecations = Set.new |
| 12 | + alias_to_canonical = {} |
| 13 | + supported_configurations = json_data[:supportedConfigurations].each.with_object({}) do |(name, configs), h| |
| 14 | + configs.each do |config| |
| 15 | + config.transform_keys!(&:to_sym) |
| 16 | + config[:aliases]&.each do |alias_name| |
| 17 | + aliases[name] ||= [] |
| 18 | + aliases[name] << alias_name |
| 19 | + alias_to_canonical[alias_name] = name |
14 | 20 |
|
15 | | - h[alias_name] = canonical |
| 21 | + # If an alias is not registered as its own config, it is by default deprecated |
| 22 | + deprecations.add(alias_name) unless json_data.dig(:supportedConfigurations, alias_name) |
| 23 | + end |
| 24 | + # Add deprecated configs with no replacement provided |
| 25 | + deprecations.add(name) if config[:deprecations] |
| 26 | + config.delete(:aliases) |
| 27 | + config.delete(:deprecations) |
16 | 28 | end |
| 29 | + h[name] = configs |
17 | 30 | end |
18 | 31 |
|
19 | 32 | error_message = <<~ERROR_MESSAGE |
20 | 33 | Configuration map mismatch between the JSON file and the generated file, please run `rake local_config_map:generate` and commit the changes. |
21 | 34 | Please refer to `docs/AccessEnvironmentVariables.md` for more information. |
22 | 35 | ERROR_MESSAGE |
23 | 36 |
|
24 | | - expect(json_data[:supportedConfigurations]).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS), error_message |
25 | | - expect(json_data[:aliases]).to eq(Datadog::Core::Configuration::ALIASES), error_message |
26 | | - expect(json_data[:deprecations]).to eq(Datadog::Core::Configuration::DEPRECATIONS), error_message |
| 37 | + expect(supported_configurations).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS), error_message |
| 38 | + # check order of the keys |
| 39 | + expect(supported_configurations.keys).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS.keys), |
| 40 | + "The keys in supported-configurations.json are not correctly sorted. Please keep the keys sorted alphabetically." |
| 41 | + |
| 42 | + # no need to check the order for these as they don't appear in the JSON file |
| 43 | + expect(aliases).to eq(Datadog::Core::Configuration::ALIASES), error_message |
| 44 | + expect(deprecations.to_a.sort).to eq(Datadog::Core::Configuration::DEPRECATIONS), error_message |
27 | 45 | expect(alias_to_canonical).to eq(Datadog::Core::Configuration::ALIAS_TO_CANONICAL), error_message |
28 | 46 | end |
29 | 47 | end |
|
0 commit comments