diff --git a/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml b/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml new file mode 100644 index 0000000000000000000000000000000000000000..e2550140867aaaf33d3bb6838f8859f7378b0b62 --- /dev/null +++ b/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml @@ -0,0 +1,5 @@ +--- +title: Use guard in fetch_legacy_config +merge_request: 1345 +author: +type: fixed diff --git a/ruby/gitlab-shell/lib/gitlab_config.rb b/ruby/gitlab-shell/lib/gitlab_config.rb index 086ef2fad01be98a519bdfe22abb136d9dbafebe..19f03c346d58e5bbebf3fb5a0226392a93f5573f 100644 --- a/ruby/gitlab-shell/lib/gitlab_config.rb +++ b/ruby/gitlab-shell/lib/gitlab_config.rb @@ -56,7 +56,7 @@ class GitlabConfig end def fetch_from_legacy_config(key, default) - legacy_config.fetch(key, default) + legacy_config[key] || default end private diff --git a/ruby/gitlab-shell/spec/gitlab_config_spec.rb b/ruby/gitlab-shell/spec/gitlab_config_spec.rb index af6f1358f5a57c564b5dbc0949ce60297566907a..6de0cd08e2148b7b67b2ab6a195c9147d74f28de 100644 --- a/ruby/gitlab-shell/spec/gitlab_config_spec.rb +++ b/ruby/gitlab-shell/spec/gitlab_config_spec.rb @@ -31,4 +31,25 @@ describe GitlabConfig do is_expected.to eq('text') end end + + describe '#fetch_from_legacy_config' do + let(:key) { 'yaml_key' } + + where(:yaml_value, :default, :expected_value) do + [ + ['a', 'b', 'a'], + [nil, 'b', 'b'], + ['a', nil, 'a'], + [nil, {}, {}] + ] + end + + with_them do + it 'returns the correct value' do + config_data[key] = yaml_value + + expect(config.fetch_from_legacy_config(key, default)).to eq(expected_value) + end + end + end end