Skip to content

Commit

Permalink
Merge pull request #2960 from OSC/backport-sorted-files
Browse files Browse the repository at this point in the history
backport sort ondemand.d files by name before loading (#2944)
  • Loading branch information
johrstrom committed Aug 16, 2023
2 parents 4157cb5 + bce8180 commit 431bcbb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,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, nil, "-").result(binding)
yml = YAML.safe_load(content, aliases: true) || {}
Expand Down
36 changes: 36 additions & 0 deletions apps/dashboard/test/config/configuration_singleton_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,40 @@ 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(['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
end

0 comments on commit 431bcbb

Please sign in to comment.