From 0132648ff25fe0a73ad155ca5ddfb9b34ededdbd Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Fri, 4 Aug 2023 10:51:56 -0400 Subject: [PATCH 1/2] sort ondemand.d files by name before loading --- .../config/configuration_singleton.rb | 2 +- .../config/configuration_singleton_test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/config/configuration_singleton.rb b/apps/dashboard/config/configuration_singleton.rb index 2eb5179a83..39e11ff40d 100644 --- a/apps/dashboard/config/configuration_singleton.rb +++ b/apps/dashboard/config/configuration_singleton.rb @@ -387,7 +387,7 @@ def can_access_core_app?(name) def read_config files = Pathname.glob(config_directory.join("*.{yml,yaml,yml.erb,yaml.erb}")) - files.each_with_object({}) do |f, conf| + files.sort.each_with_object({}) do |f, conf| begin content = ERB.new(f.read, trim_mode: "-").result(binding) yml = YAML.safe_load(content, aliases: true) || {} diff --git a/apps/dashboard/test/config/configuration_singleton_test.rb b/apps/dashboard/test/config/configuration_singleton_test.rb index cc80b8c651..5458a7498d 100644 --- a/apps/dashboard/test/config/configuration_singleton_test.rb +++ b/apps/dashboard/test/config/configuration_singleton_test.rb @@ -460,4 +460,22 @@ def no_config_env end end end + + test 'config files are sorted by name' do + Dir.mktmpdir do |dir| + with_modified_env({ OOD_CONFIG_D_DIRECTORY: dir.to_s }) do + a_config = { 'nav_categories' => ['AAA', 'BBB'] } + z_config = { 'nav_categories' => ['YYY', 'ZZZ'] } + + File.open("#{dir}/a_config.yml", 'w+') { |f| f.write(a_config.to_yaml) } + File.open("#{dir}/z_config.yml", 'w+') { |f| f.write(z_config.to_yaml) } + + config = ConfigurationSingleton.new.config + nav = config.fetch(:nav_categories) + + # z_config has overwritten a_config + assert_equal(nav, ['YYY', 'ZZZ']) + end + end + end end From c9cc36d17e33b51de75c10900b05bfe45f9f93ae Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Fri, 4 Aug 2023 10:57:31 -0400 Subject: [PATCH 2/2] add test for numbers too --- .../config/configuration_singleton_test.rb | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/test/config/configuration_singleton_test.rb b/apps/dashboard/test/config/configuration_singleton_test.rb index 5458a7498d..c4328dfb83 100644 --- a/apps/dashboard/test/config/configuration_singleton_test.rb +++ b/apps/dashboard/test/config/configuration_singleton_test.rb @@ -474,7 +474,25 @@ def no_config_env nav = config.fetch(:nav_categories) # z_config has overwritten a_config - assert_equal(nav, ['YYY', 'ZZZ']) + assert_equal(['YYY', 'ZZZ'], nav) + end + end + end + + test 'config files are sorted by name with numbers' do + Dir.mktmpdir do |dir| + with_modified_env({ OOD_CONFIG_D_DIRECTORY: dir.to_s }) do + zero_config = { 'nav_categories' => ['AAA', 'BBB'] } + one_config = { 'nav_categories' => ['YYY', 'ZZZ'] } + + File.open("#{dir}/00_config.yml", 'w+') { |f| f.write(zero_config.to_yaml) } + File.open("#{dir}/01_config.yml", 'w+') { |f| f.write(one_config.to_yaml) } + + config = ConfigurationSingleton.new.config + nav = config.fetch(:nav_categories) + + # z_config has overwritten a_config + assert_equal(['YYY', 'ZZZ'], nav) end end end